IOS registration local notifications (push)

Source: Internet
Author: User

Note: Press the home button to get the app to run in the background before you can view notifications.


-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {

//Override point for customization after application launch.

// Register for local notifications

Uilocalnotification *localnotifit = [[Uilocalnotification alloc] init];

if (Localnotifit) {

// Get notification time

NSDate *now = [NSDate Date];

Localnotifit.timezone = [Nstimezone defaulttimezone];

start notification after //ten seconds

Localnotifit.firedate = [now datebyaddingtimeinterval:10.0];

//repeat interval (lower limit is per minute notification)

Localnotifit.repeatinterval = Kcfcalendarunitminute;

// reminder content

Localnotifit.alertbody = @ "The phone will explode in 10 seconds and throw it away ";

// lock screen status," swipe to "(these three words are the system automatically appears) immediately after the text is alertaction

Localnotifit.alertaction = @ " unlock (enter App)";

//Notification title in the notification bar

Localnotifit.alerttitle = @ " hint ";

// default notification sound (only heard on the real machine)

Localnotifit.soundname = Uilocalnotificationdefaultsoundname;

// red circle number

Localnotifit.applicationiconbadgenumber = 1;

// notification identification

Nsmutabledictionary *dic = [nsmutabledictionary dictionarywithobject:@ "Localnotificationid" forKey:@ "key"];

Localnotifit.userinfo = dic;

// Add notifications to the system

[[UIApplication sharedapplication] schedulelocalnotification:localnotifit];

}

//Registration Notice (registration notification method after iOS 8, iOS 8 not previously introduced)

Uiusernotificationsettings *settings = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypealert | Uiusernotificationtypebadge | Uiusernotificationtypesound Categories:nil];

[[UIApplication sharedapplication] registerusernotificationsettings:settings];

return YES;

}


The method that is triggered after receiving the notification will only be executed when the App enters the foreground.

-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification

{

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ " hint " message:@ " congratulations on your being fooled " Delegate:nil Cancelbuttontitle:nil otherbuttontitles:@ " I'm happy ", nil];

[UIApplication sharedapplication].applicationiconbadgenumber = 0;

[Alert show];

Cancel Notification

[[UIApplication sharedapplication] cancelalllocalnotifications];

}



IOS registration local notifications (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.