creates a local message when the user leaves the application. if the user needs to set some configuration information when using the application, use the class message with caution.
Suppose an application runs in the foreground. When the app switches from the home button to the background, 1 seconds later, you can see the popup information (iOS 5 and iOS 4 devices).
If the user taps this message, the application can be restored to the foreground.
The implementation code is very simple, create a NSDate object at the beginning, record the current date and time, add 1 seconds on this object, sets the trigger time for local messages. Set up local notification messages and packages, and schedule notifications with the operating system.
Add the following code to the DELEGATE.M file: -(void) Applicationdidenterbackground: (uiapplication *) application { uilocalnotification *localnotification = [[[[Uilocalnotification alloc] init] autorelease]; //Current date nsdate *date = [NSDate date]; //Add One Second to the current time nsdate *datetofire = [date datebyaddingtimeinterval:1]; //Set The fire date/time [localnotification Setfiredate:datetofire]; [localnotification settimezone:[nstimezone defaulttimezone]]; / /SETUP Alert notification [localnotification setalertbody:@ "tap to return to TestApp"]; [localnotification setalertaction:@ "Open TestApp"]; [localnotification Sethasaction:yes]; [[uiapplication sharedapplication] schedulelocalnotification:localnotification]; }
when the message box pops up, after the user clicks, the following method can be executed once the application is restored to the foreground -(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) Notification { Your code here ... } |
iOS local push-alert feature