2013-08-23 2 views
0

응용 프로그램을 최소화, 모두 잘하지만, 나는 붐이 오류를, 무슨 배포 할 때 * 인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는 : '* - [__ NSArrayM 은 insertObject : atIndex :] : 개체가지역 알림 오류 아이폰 OS

-(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]; 
    } 
    } 
} 

답변

0

제안의 커플 'nil을 할 수 없습니다

첫째; 대신 applicationWillResignActive에 코드를 넣으려고 했습니까?

코드에서 UIApplication에 대한 참조를 얻는 이유는 무엇입니까? 메소드에 대한 매개 변수로 이미 이것을 가지고 있습니다 ...

코드에 중단 점을 넣으면이 오류가 발생한 위치를 정확하게보십시오. 나는 그것이 [app scheduleLocalNotification : notifyAlarm]의 마지막 줄에서 일어난다 고 생각할 것이다. 그리고 어떤 이유로 notifyAlarm 객체가 nil이기 때문에 발생한다. 디버거를 사용하여 코드를 단계별로 실행하여 해당 객체가 실제로 설정되는지 확인합니다.

또한; 코드가 비활성화 될 때까지 최대 5 초가 걸릴 수 있습니다. 일시 중지 된 경우; 코드를 실행할 수 없습니다. 예를 들어, 어떤 이유로 NSURLConnection 요청이 응답하는 데 오래 걸리면 코드가 끝나기 전에 앱이 일시 중지됩니다.