- iOS8 send local notifications, you need to register local notifications first.
if ([[uiapplication sharedapplication]currentusernotificationsettings]. Types= =Uiusernotificationtypenone) currently applied local notification type, uiusernotificationtypenone not registered local notification registration is System level, Not related to the program, when the program is removed after the reinstallation is still authorized, the ID is bound.
Each time the authorization operation is performed, it will go this agent-(void) Application: (UIApplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings;
- Uiusernotificationtypenone = 0, //application must not present any user interface at the time of receiving the notification
- Uiusernotificationtypebadge = 1 << 0, //The application can mark its icon as
- Uiusernotificationtypesound = 1 << 1, //The app can make a sound after receiving a notification
- Uiusernotificationtypealert = 1 << 2, //The application can display alerts after notification is received
- (corresponding mark, sound, Banner)
The actual development is divided into two situations 1. When the application exits to the background, click Push to enter the program. This time can be by using-(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) notification; Gets the push information according to this method. 2. When the app is killed, the interface is reloaded when the push comes in. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions; You can get push content based on launchoptions. Receive notification parameters uilocalnotification *notification=[launchoptions Valueforkey: Uiapplicationlaunchoptionslocalnotificationkey];
-(void) addnotification{ uilocalnotification *notification=[[uilocalnotification alloc]init]; Notification.firedate=[nsdate Datewithtimeintervalsincenow:10]; [Email protected] "notice"; [[UIApplication sharedapplication]schedulelocalnotification:notification];}
Implement a small function: When the user does not operate for 1 hours in a row will be prompted by local push user action, every 1 hours prompt. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {// Notification authorization if ([[UIApplication Sharedapplication]currentusernotificationsettings].types==uiusernotificationtypenone) { [[UIApplication sharedapplication] registerusernotificationsettings:[uiusernotificationsettings settingsForTypes: Uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound Categories:nil]]; }}//lost Focus-(void) Applicationwillresignactive: (uiapplication *) application{[self addnotification];} -(void) addnotification{uilocalnotification *notification=[[uilocalnotification Alloc]init]; Notification.firedate=[nsdate Datewithtimeintervalsincenow:10]; [email protected] "One minute no use"; notification.repeatinterval=nscalendarunitminute;//set the frequency of repetition [[UIApplication sharedapplication] Schedulelocalnotification:notification];} Clear all local notifications [[UIApplication sharedapplication]cancelalllocalNotifications];
ios--Local Notifications