Not much to say directly on the code
#import "AppDelegate.h"
@interface Appdelegate ()
@end
@implementation Appdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
Override point for customization after application launch.
If you have received authorization to send notifications, create a local notification, or request authorization (note: If you do not request authorization in the settings there is no corresponding notification settings item, that is, if the request has never been sent, even through the settings can not open the message allowed setting)
if ([[UIApplication sharedapplication]currentusernotificationsettings].types!=uiusernotificationtypenone) {
[Self addlocalnotification];
}else{
[[UIApplication Sharedapplication]registerusernotificationsettings:[uiusernotificationsettings Settingsfortypes:uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound Categories:nil]];
//}
return YES;
}
#pragma mark executes after the user registration notification method has been called (that is, after the Registerusernotificationsettings: method is executed)
-(void) Application: (UIApplication *) application didregisterusernotificationsettings: (Uiusernotificationsettings * ) notificationsettings{
if (Notificationsettings.types!=uiusernotificationtypenone) {
[Self addlocalnotification];
}
}
#pragma mark enters the foreground to set up message information
-(void) Applicationwillenterforeground: (uiapplication *) application{
[[UIApplication sharedapplication]setapplicationiconbadgenumber:0];//enter foreground to cancel app message icon
}
#pragma mark-Private method
#pragma mark Add local notifications
-(void) addlocalnotification{
Defining local Notification objects
Uilocalnotification *notification=[[uilocalnotification Alloc]init];
Set call time
Notification.firedate=[nsdate datewithtimeintervalsincenow:10.0];//notification trigger time, after 10s
notification.repeatinterval=2;//Notification Repeat Count
Notification.repeatcalendar=[nscalendar currentcalendar];//The current calendar, it is best to set the time zone and other information to enable automatic synchronization
Set notification properties
[Email protected] "Recently added a lot of interesting features, whether to experience now?" "; Notification body
notification.applicationiconbadgenumber=1;//the number of messages displayed in the upper-right corner of the application icon
[Email protected] "open app"; Sliding action tips for the Standby interface
[Email protected] "Default";//click the notification to open the app when the start picture, here to use the program to start the picture
notification.soundname=uilocalnotificationdefaultsoundname;//The sound that is played when the notification is received, the default message sound
[Email protected] "MSG.CAF";//notification sound (requires real machine to hear sound)
Set up user information
[Email protected] {@ "id": @1,@ "User": @ "Kenshin Cui"};//Other additional information bound to the notification
Invoke notification
[[UIApplication sharedapplication] schedulelocalnotification:notification];
}
#pragma mark Remove local notifications and remember to remove them when this notification is not required
-(void) removenotification{
[[UIApplication sharedapplication] cancelalllocalnotifications];
}
iOS development-Local push notifications