Push UILocalNotification locally in iOS

Source: Internet
Author: User

Push UILocalNotification locally in iOS
Create notification

 

 

UILocalNotification * notification = [[UILocalNotification alloc] init]; if (notification) {NSDate * now = [NSDate new]; notification. fireDate = [now dateByAddingTimeInterval: 10]; // notification after 10 seconds. repeatInterval = 0; // number of repetitions, kCFCalendarUnitWeekday notification once a week. timeZone = [NSTimeZone defaultTimeZone]; // set the time zone notification. applicationIconBadgeNumber = 1; // The application badge notification. soundName = UILocalNotificationDefaultSoundName; // sound, which can be changed to alarm. soundName = @sound.wav // remove the following two lines and the notification box will not pop up. alertBody = @ notification content; // The prompt box notification is displayed. alertAction = @ open; // prompt box button // notification. hasAction = NO; // whether to display additional buttons. If no is displayed, alertAction disappears NSDictionary * infoDict = [NSDictionary dictionaryWithObject: @ value forKey: @ key]; // set userinfo so that other values can be passed when you need to undo it later. notification can be obtained when a notification is triggered. userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification: notification];}

 


Pushed content
// Push content-(void) application :( UIApplication *) application didReceiveLocalNotification :( UILocalNotification *) notification {// here, you can use useinfo of notification, if ([[notification. userInfo objectForKey: @ key] isEqualToString: @ value]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ system prompt message: @ your system has a serious threat delegate: nil cancelButtonTitle: @ disable otherButtonTitles: nil, nil]; [alert show];} application. applicationIconBadgeNumber = 0; // remove badge}

-(Void) applicationDidBecomeActive :( UIApplication *) application {// if the application is not pushed, the application icon is used to open the application and remove the badge application. applicationIconBadgeNumber = 0 ;}

Cancellation notification
// Obtain all current local notifications NSArray * notificaitons = [[UIApplication sharedApplication] scheduledlocalconfigurications]; if (! Notificaitons | notificaitons. count <= 0) {return;} // cancel a specific notification for (UILocalNotification * Every y in every icaitons) {if ([[every Y. userInfo objectForKey: @ key] isEqualToString: @ value]) {[[UIApplication sharedApplication] cancelLocalNotification: Policy]; break ;}} /// cancel all local notifications // [[[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.