gpt4 book ai didi

ios - 应用程序因 NSInvalidArgumentException 而崩溃

转载 作者:行者123 更新时间:2023-11-28 21:56:57 25 4
gpt4 key购买 nike

我正在尝试向 map View 添加注释。每个注释代表一条推文。我从 twitter api 获取每条推文的坐标。该应用程序在加载 map 后立即崩溃。我不确定为什么。

编辑:这是相关代码的当前版本。它运行良好,直到出现 tweetLocation 为 null 的推文。然后它崩溃了。

STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"key" consumerSecret:@"secret"];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {

[twitter getSearchTweetsWithQuery:@"apple" geocode:geoCode lang:nil locale:nil resultType:@"recent" count:@"10" until:nil sinceID:nil maxID:nil includeEntities:nil callback:nil successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {

tweetsArray = [NSMutableArray arrayWithArray:statuses];
NSLog(@"tweetsArray: %@", tweetsArray);

for (int i = 0; i < [tweetsArray count]; i++) {
NSDictionary *t = tweetsArray[i];
tweetAnnotation = [[MKPointAnnotation alloc]init];

NSArray *tweetLocation = [[t valueForKey:@"geo"]valueForKey:@"coordinates"];
NSLog(@"Tweet Location: %@", tweetLocation);

if ([tweetLocation count] == 0) {
continue;
}
else {
double lat = [[tweetLocation objectAtIndex:0]doubleValue];
double longitude = [[tweetLocation objectAtIndex:1]doubleValue];
locationCoord.latitude = lat;
locationCoord.longitude = longitude;

twitterName = [t valueForKeyPath:@"user.screen_name"];
NSLog(@"Twitter name: %@", twitterName);
tweetAnnotation.title = twitterName;

tweetAnnotation.coordinate = locationCoord;
[tweetLocationsArray addObject:tweetAnnotation];
}
}

[tweetMap addAnnotations:tweetLocationsArray];

} errorBlock:^(NSError *error) {

NSLog(@"%@", error.debugDescription);

}];

} errorBlock:^(NSError *error) {

NSLog(@"%@", error.debugDescription);

}];

编辑:这是控制台中的当前错误:

2014-10-07 08:00:36.278 Tweets By Location[5244:382886] Tweet Location: (
"37.33158914",
"-122.03076495"
)
2014-10-07 08:00:36.278 Tweets By Location[5244:382886] Twitter name: tofuhunter
2014-10-07 08:00:36.278 Tweets By Location[5244:382886] Tweet Location: (
"37.33161957",
"-122.03080173"
)
2014-10-07 08:00:36.278 Tweets By Location[5244:382886] Twitter name: treynesss
2014-10-07 08:00:36.278 Tweets By Location[5244:382886] Tweet Location: (
"37.33161957",
"-122.03080173"
)
2014-10-07 08:00:36.279 Tweets By Location[5244:382886] Twitter name: mattlarowe
2014-10-07 08:00:36.279 Tweets By Location[5244:382886] Tweet Location: <null>
2014-10-07 08:00:36.279 Tweets By Location[5244:382886] -[NSNull count]: unrecognized selector sent to instance 0x10b0accb0
2014-10-07 08:00:36.281 Tweets By Location[5244:382886] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull count]: unrecognized selector sent to instance 0x10b0accb0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ae043f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010aa9dbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ae0b50d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010ad637fc ___forwarding___ + 988
4 CoreFoundation 0x000000010ad63398 _CF_forwarding_prep_0 + 120
5 Tweets By Location 0x000000010a08876e __32-[MapViewController viewDidLoad]_block_invoke_2 + 542
6 Tweets By Location 0x000000010a029feb __147-[STTwitterAPI getSearchTweetsWithQuery:geocode:lang:locale:resultType:count:until:sinceID:maxID:includeEntities:callback:successBlock:errorBlock:]_block_invoke + 203
7 Tweets By Location 0x000000010a01cd1a __99-[STTwitterAPI getResource:baseURLString:parameters:downloadProgressBlock:successBlock:errorBlock:]_block_invoke117 + 186
8 Tweets By Location 0x000000010a0751d8 __95-[STTwitterAppOnly getResource:baseURLString:parameters:progressBlock:successBlock:errorBlock:]_block_invoke104 + 184
9 Tweets By Location 0x000000010a065a32 __158+[STHTTPRequest(STTwitter) twitterRequestWithURLString:stTwitterUploadProgressBlock:stTwitterDownloadProgressBlock:stTwitterSuccessBlock:stTwitterErrorBlock:]_block_invoke33 + 722
10 Tweets By Location 0x000000010a071538 -[STHTTPRequest connectionDidFinishLoading:] + 472
11 CFNetwork 0x00000001105212cc __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
12 CFNetwork 0x0000000110521270 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
13 CFNetwork 0x00000001105213d7 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
14 CFNetwork 0x00000001103f25f7 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
15 CFNetwork 0x00000001104be871 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
16 CFNetwork 0x00000001103ddb36 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
17 CoreFoundation 0x000000010ad0c714 CFArrayApplyFunction + 68
18 CFNetwork 0x00000001103dd9f7 _ZN19RunloopBlockContext7performEv + 133
19 CFNetwork 0x00000001103dd836 _ZN17MultiplexerSource7performEv + 256
20 CFNetwork 0x00000001103dd64c _ZN17MultiplexerSource8_performEPv + 72
21 CoreFoundation 0x000000010ad39ad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010ad2f99d __CFRunLoopDoSources0 + 269
23 CoreFoundation 0x000000010ad2efd4 __CFRunLoopRun + 868
24 CoreFoundation 0x000000010ad2ea06 CFRunLoopRunSpecific + 470
25 GraphicsServices 0x000000010cf2f9f0 GSEventRunModal + 161
26 UIKit 0x000000010b277550 UIApplicationMain + 1282
27 Tweets By Location 0x000000010a089e43 main + 115
28 libdyld.dylib 0x000000010cb78145 start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

元素 "coordinates" 不是字符串。

根据文档,您正在遍历的对象是 Tweet 对象: https://dev.twitter.com/overview/api/tweets

coordinates 部分类似于此示例:

  "coordinates":
[
-75.14310264,
40.05701649
]

您应该将 coordinates 解析为表示(经度、纬度)对的数组。

请注意,coordinates 可能为 null(与 [NSNull null] 相比),因此您也应该考虑到这一点。

关于ios - 应用程序因 NSInvalidArgumentException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26222136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com