0
最小化應用程序時
,一切都很好,但是當我嘗試部署熱潮回事,這個錯誤 *終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「* - [__ NSArrayM insertObject:atIndex:]:對象不能是零」本地通知錯誤的iOS
-(void) applicationDidEnterBackground:(UIApplication *)application
{
NSDate *alertTime = [[NSDate date] dateByAddingTimeInterval:5];
UIApplication* app = [[UIApplication sharedApplication] init];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:kAllNews]];
NSError *error = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSError *jsonParsingError = nil;
sortArray = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
if (notifyAlarm)
{
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"news"])
{
newsNew = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"news"]];
}
if (newsNew.count > sortArray.count) {
notifyAlarm.fireDate = alertTime;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval = 0;
notifyAlarm.soundName = @"Glass.aiff";
notifyAlarm.alertAction = @"Gipoteza";
notifyAlarm.alertBody = @"Добавлена новая новость";
[app scheduleLocalNotification:notifyAlarm];
}
}
}