-(BOOL) Application: (uiapplication *) application didfinishlaunchingwithoptions: ( Nsdictionary *) launchoptions {
self. window = [[UIWindowalloc] initwithframe: [[uiscreen Mainscreen] bounds];
self. Window. Rootviewcontroller = [[viewcontrolleralloc] init];
// Ask the user for authorization before registering a notification if the user consents to the notification, or request authorization
if([[uiapplicationsharedapplication] Currentusernotificationsettings]. Types != Uiusernotificationtypenone) {
// Register a notification
[self addlocalnotification];
}Else{
// request authorization, and set the type of notification . There is a hint box, theApp icon in the top right corner of the number, a hint of the sound
[ [uiapplicationsharedapplication] registerusernotificationsettings: [ uiusernotificationsettings settingsfortypes:uiusernotificationtypealert| Uiusernotificationtypebadge| UiusernotificationtypesoundCategories:nil]];
}
self. window . BackgroundColor = [uicolorwhitecolor];
[self. window makekeyandvisible];
//Override point for customization after application launch.
return YES;
}
// user authorization after calling
-(void) Application: (uiapplication *) application didregisterusernotificationsettings: ( Uiusernotificationsettings *) notificationsettings
{
// If User License notification, add a notification
if (Notificationsettings. types ! =Uiusernotificationtypenone) {
[self addlocalnotification];
}
}
// open app
-(void) Applicationwillenterforeground: (uiapplication *) application
{
// Set the number in the upper-right corner of icon to 0
[[uiapplicationsharedapplication] setapplicationiconbadgenumber: 0 ];
}
#pragma mark- add a local notification
-(void) addlocalnotification
{
uilocalnotification *notification = [[ uilocalnotification alloc " init ];
notification. firedate = [nsdatedatewithtimeintervalsincenow:ten]; //10 seconds after reminder
Notification. repeatinterval =2; // Number of repetitions
Notification. alertbody =@ " long time no play, come to play "; // Tips For information
notification. Applicationiconbadgenumber =1; // the number in the upper right corner
Notification. alertaction =@ " open App"; // subtitle Prompt statement when sliding to unlock
Notification. alertlaunchimage =@ "1.png"; // swipe to unlock pictures that appear when you enter the app
Notification. soundname =@ "MSG.CAF"; // you need a real machine to hear the sound .
Notification. userInfo =@{@ "id":@1,@ "user":@ "LuCa"}; // Some additional information on the notification
// Call notification
[[uiapplicationsharedapplication] schedulelocalnotification: Notification];
}
// Remove the notification if you do not need a local notification
-(void) removenotification
{
[[uiapplicationsharedapplication] cancelalllocalnotifications];
}
iOS local push