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)