![](/img/trans.png)
[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: -[__NSCFString scheme]: unrecognized selector sent to instance
[英]Terminating app - 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance
我在有人創建的iOS應用中有以下代碼。 但是,應用程序的這一部分會中斷並使其崩潰。
if([[dictHomeSettings allKeys] containsObject:@"notify_url"]) {
NSString *notifyUrl = [dictHomeSettings objectForKey:@"notify_url"];
if(notifyUrl.length>0) {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
// // You may want to cache this explicitly instead of reloading every time.
// NSData *notifyData = [NSData dataWithContentsOfURL:[NSURL URLWithString:notifyUrl]];
// NSError* error;
// NSDictionary* json = [NSJSONSerialization JSONObjectWithData:notifyData
// options:kNilOptions
// error:&error];
XMLDictionaryParser *xmlParser = [XMLDictionaryParser new];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:notifyUrl]];
NSDictionary *aDict = [xmlParser dictionaryWithParser:parser];
dispatch_async(dispatch_get_main_queue(), ^{
//NSLog(@"myNsArray : %@",aDict);
if([[aDict allKeys] containsObject:@"Notification"]) {
NSArray *array = [aDict objectForKey:@"Notification"];
if(array.count>0) {
[Common deletePreviousLocalNotifications];
for(NSDictionary *dictNotification in array) {
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
if([Common compareDate:[dictNotification objectForKey:@"StartTime"] isGreaterThanOrEqualDate:[dateFormatter stringFromDate:[NSDate date]]]) {
NSLog(@"adding notification : %@",dictNotification);
[Common addLocalNotificationAtDateTime:[dateFormatter dateFromString:[dictNotification objectForKey:@"StartTime"]] AlertBody:[dictNotification objectForKey:@"Message"] UserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[dictNotification objectForKey:@"URL"], @"URL", nil]];
}
}
}
}
});
});
您正在嘗試在NSString對象上調用“ objectForKey”。 請檢查您假定為NSDictionary對象的對象是否實際上是NSDictionary對象實例。
顯然,您試圖在NSString
對象上調用objectForKey 。 如圖所示[dictNotification objectForKey:@"StartTime"]
是一個Number
值,但您假設它是一個字符串(對此我不確定)。 因此,您在此通話中遇到了error
[Common compareDate:(Number *) isGreaterThanOrEqualDate:(NSString *)];
您可以在[NSObject doesNotRecognizeSelector:]
上設置帶有此符號的Symbolic breakpoint
,以方便地debug
代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.