我的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]];
}
}
}
}
});
});
答案 0 :(得分:0)
你试图打电话给#34; objectForKey"在NSString对象上。请检查您认为是NSDictionary对象的对象是否实际是NSDictionary对象实例。
答案 1 :(得分:0)
显然,您正试图在NSString
对象上调用 objectForKey 。如所观察到的[dictNotification objectForKey:@"StartTime"]
是Number
值,但您假设它是一个字符串(我不确定)。所以你在这次电话会议上得到error
[Common compareDate:(Number *) isGreaterThanOrEqualDate:(NSString *)];
您可以在Symbolic breakpoint
上设置带有此符号的[NSObject doesNotRecognizeSelector:]
,以便轻松debug
代码。