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];
}