Local Notification Error iOS -


when minimizing application, well, when try deploy boom going on, error * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[__nsarraym insertobject:atindex:]: object cannot nil'

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

a couple of suggestions:

first; did try putting code in applicationwillresignactive instead?

why getting reference uiapplication in code? have parameter method...

try putting breakpoints in code see error occurs. guess happens on last line: [app schedulelocalnotification:notifyalarm], , happens because notifyalarm object reason nil. use debugger step through code see if object indeed set.

also; aware code has maximum of 5 seconds deactivation until becomes suspended. when suspended; no code can run. if, example, nsurlconnection request reason takes long respond, app suspended before code finished.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -