in iOS, there are two kinds of information prompt push method, one kind is remote server push (APNS) , there is a kind of local notice uilocalnotification, today to briefly record the use of uilocalnotification, the details are as follows:
Uilocalnotification *notifity=[[uilocalnotification alloc] init]; NSDateFormatter *formattr=[[nsdateformatter alloc] init];
Format Time [formattr setdateformat:@ "hh:mm"]; Trigger notification time nsdate *now=[formattr datefromstring:[nsstring stringwithformat:@ "%@", Strtimer]]; Notifity.firedate=now; Time zone notifity.timezone=[nstimezone Defaulttimezone]; The unit that notifies the repeating prompt, which can be weeks (nsweekdaycalendarunit) minutes (nsminutecalendarunit) seconds (nssecondcalendarunit) months (nsmonthcalendarunit) years ( Nsyearcalendarunit)
Notifity.repeatinterval=nsdaycalendarunit;
Notification content [email protected] "This is a notice"; The sound notifity.soundname=uilocalnotificationdefaultsoundname to be played when the notification is triggered ; Perform notification registration [[uiapplication sharedapplication] schedulelocalnotification:notifity];
If you want to carry parameter information in the notification bar, you can use the following method:
Nsdictionary *dic = [nsdictionary dictionarywithobject:@ "name" forkey:@ "key "]; = dic;
If the software is running, you can get and process the parameter information through the callback method in Appdelegate:
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification{ if (notification) { nsdictionary *userinfo = notification.userinfo; NSString *obj = [userInfo objectforkey:@ "key"]; NSLog (@ "%@", obj);} }
In addition, there are two ways to unregister a local notification, one is to cancel the specified notification, and the second is to cancel all registration notifications:
[[UIApplication sharedapplication] cancellocalnotification:localnotification]; [[UIApplication sharedapplication] cancelalllocalnotification];
The above is what I learned today, recorded here and shared with you, if you have any questions, please point out the joint study!