1. Introduction
Local notifications are triggered by a local app, which is a form of notification based on time behavior, such as alarm timing, to-do reminders, or when an app is not used for a period of time and is usually prompted to use the app, etc. are local notifications.
2. Create Uilocalnotification
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.uilocalnotification*localnotifi = [UilocalnotificationNew]; Localnotifi.firedate= [NSDate Datewithtimeintervalsincenow:5];//Send TimeLocalnotifi.alertbody =@"This is a local push";//Set Reminder ContentLocalnotifi.soundname = Uilocalnotificationdefaultsoundname;//Set Push soundLocalnotifi.applicationiconbadgenumber = -;//set icon mark in top right corner of app//localnotifi.hasaction = YES;//whether to display content when the lock screen, default Yes to set the reminder button text//localnotifi.alertaction = @ "good";//button TextLocalnotifi.timezone = [Nstimezone defaulttimezone];//set time zone [Nstimezone Defaulttimezone], follow the phone's time zoneLocalnotifi.repeatinterval = Nscalendarunitminute;//sets the minimum unit of time that repeats are sent every few minutes. 0 means do not repeat, this property is set, then the dispatch pool will not run out of release! Need to manually delete notification objectsLocalnotifi.repeatcalendar = [Nscalendar calendarwithidentifier:@"Nscalendaridentifierchinese"];//set dependent calendar calendars, the default is to follow the system to go, the calendar is not the same as the monthly recurrence interval is different (such as the lunar calendar is 30 days) if(@available (IOS8.2, *) ) {Localnotifi.alerttitle=@"local push-Oh"; } Else { //Fallback on earlier versions}//Set PopOver titleUimutableusernotificationcategory *category = [uimutableusernotificationcategoryNew];//using variable subclassesCategory.identifier =@"category";//set identifiers, and note the same as the category identifiers that send notification settings//Set the foreground button, click to make the program back to the foreground button called the front deskUimutableusernotificationaction *actionleft = [uimutableusernotificationactionNew]; Actionleft.identifier=@" Left"; Actionleft.activationmode=Uiusernotificationactivationmodeforeground; Actionleft.title=@"Front button"; //Set the Background button, click on the program also in the background, such as QQ messageUimutableusernotificationaction *actionright = [uimutableusernotificationactionNew]; Actionright.identifier=@" Right"; Actionright.activationmode=Uiusernotificationactivationmodebackground; Actionright.title=@"Background button"; [Category Setactions:@[actionleft,actionright] forcontext:uiusernotificationactioncontextdefault]; Nsset*catogoryset =[Nsset setwithobject:category]; Localnotifi.category=@"category";//in which area to send the notification, enter this area to send this notice, you can come in and tune out once//@property (Nullable, nonatomic,copy) clregion *region Ns_available_ios (8_0);//@property (nonatomic,assign) BOOL regiontriggersonce Ns_available_ios (8_0), whether the zone is only detected once//@property (Nullable, nonatomic,copy) NSString *alertlaunchimage; set boot picture//@property (Nullable, nonatomic,copy) nsdictionary *userinfo; push carrying parameters//@property (Nullable, nonatomic, copy) NSString *category Ns_available_ios (8_0); Add a drop-down quick reply function if(ios8_or_later) {//Uiusernotificationtype enumeration://uiusernotificationtypenone = 0,//Uiusernotificationtypebadge = 1 << 0,//icon Marker//uiusernotificationtypesound = 1 << 1,//Sound//Uiusernotificationtypealert = 1 << 2,//Reminders////categories: For adding a drop-down quick reply functionUiusernotificationsettings *settings = [Uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge| uiusernotificationtypesound|Uiusernotificationtypealert Categories:catogoryset]; [[UIApplication sharedapplication] registerusernotificationsettings:settings]; } //dispatching local push notifications (dispatched at a specific time after Firedata)//[[UIApplication sharedapplication] schedulelocalnotification:localnotifi]; //send local notifications now[[UIApplication sharedapplication] presentlocalnotificationnow:localnotifi]; //processing the notification after the click, the program started to get the notification object, if the first boot has not sent a notification, the first notification object is empty, there is no need to process the notification if(Launchoptions[uiapplicationlaunchoptionslocalnotificationkey]) {uilocalnotification*localnotifi =Launchoptions[uiapplicationlaunchoptionslocalnotificationkey]; [Self changelocalnotifi:localnotifi]; } returnYES;}
3. Removal of push notifications
-(void ) deletelocalnotifi{ // Delete all notifications [[ UIApplication sharedapplication] cancelalllocalnotifications]; // Delete the specified notification (sending an expired push is not in this array) Nsarray * Notifiarr = [[UIApplication sharedapplication] scheduledlocalnotifications]; for (uilocalnotification *localnoti in Notifiarr) { // According to the value of userinfo, to see if this is the notification you want to delete if (localnoti.userinfo) {[[UIApplication sharedapplication] Cancellocalnotification : Localnoti]; } }}
4, you receive the push processing method
//Handling Notifications- (void) Changelocalnotifi: (Uilocalnotification *) localnotifi{//If you return directly from the foreground if([uiapplication Sharedapplication].applicationstate = =uiapplicationstateactive) { return; } //Get notification Information//Localnotifi.userinfo}//call the program foreground or background after receiving a local notification is not useful, exit cannot receive the message- (void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) notification{[self changelocalnotifi:notification];}
5, foreground and background button processing method
// Front and Back button handling methods -(void) Application: (UIApplication *) application Handleactionwithidentifier: ( NSString *) identifier forlocalnotification: (uilocalnotification *) notification Completionhandler: (void (^) (void)) completionhandler{ // We can get identifiers here, judging by the identifier is the foreground button or the back button or the god Horse button, Perform related logic processing (such as reply message) NSLog (@ "identifier:%@", identifier) ; // Once you accept the method that must be called (Tell the system when it ends, the system is provisioning itself internally) Completionhandler ();}
6. Remote push
https://www.jianshu.com/p/25e267037f6e
iOS development local push