iOS local push

Source: Internet
Author: User

-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.