Register local notifications (push) for iOS)

Source: Internet
Author: User

Register local notifications (push) for iOS)

Note: You can view notifications only when you press the Home Key to enable the App to run in the background.

 

 

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {

// Override point for customization after application launch.

 

// Register a local notification

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

If (localcmdit ){

 

// Obtain the notification time

NSDate * now = [NSDate date];

Localnotifit. timeZone = [NSTimeZone defaultTimeZone];

 

// Notification starts in 10 seconds

Local1_it. fireDate = [now dateByAddingTimeInterval: 10.0];

 

// Repetition interval (minimum value: One notification per minute)

Localnotifit. repeatInterval = kCFCalendarUnitMinute;

 

// Reminder content

Local‑it. alertBody = @ 10 seconds later, the phone will pop up and you can discard it immediately;

 

// In the screen lock status, the text following "slide" (these three words appear automatically) is "alertAction ".

Localtailit. alertAction = @ unlock (enter the App );

 

// Notification title in the notification bar

Local‑it. alertTitle = @ prompt;

 

// Default notification sound (only on a real machine)

Localnotifit. soundName = uilocalnotificationdefasoundname;

 

// Red circle number

Localnotifit. applicationIconBadgeNumber = 1;

 

// Notification ID

NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObject: @ LocalNotificationID forKey: @ key];

Local‑it. userInfo = dic;

 

// Add the notification to the System

[[UIApplication sharedApplication] scheduleLocalNotification: local1_it];

 

}

 

// Registration notification (the Registration notification method after iOS 8 is not introduced before iOS 8)

UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories: nil]; www.bkjia.com

[[UIApplication sharedApplication] registerUserNotificationSettings: settings];

 

Return YES;

}

 

// Method triggered after the notification is received. It is executed only when the App enters the foreground.

-(Void) application :( UIApplication *) application didReceiveLocalNotification :( UILocalNotification *) notification

{

UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ prompt message: @ congratulations! delegate: nil cancelButtonTitle: nil otherButtonTitles: @ I am very happy, nil];

[UIApplication sharedApplication]. applicationIconBadgeNumber = 0;

[Alert show];

 

// Cancel notification

// [[UIApplication sharedApplication] cancelalllocalconfigurications];

}



Related Article

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.