IOS local push implementation, compatible with iOS 8

Source: Internet
Author: User

IOS local push implementation, compatible with iOS 8

Code in AppDelegate. m

// AppDelegate. m medium-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// process the problem that iOS8 cannot receive locally. float sysVersion = [[UIDevice currentDevice] systemVersion]. floatValue; if (sysVersion> = 8.0) {UIUserNotificationType = metric | uiusernotiftypetypesound; UIUserNotificationSettings * setting = [UIUserNotificationSettings Syntax: type categories: nil]; [UIApplication sharedApplication] usage: setting];} return YES ;}

// Receive local push (AppDelegate. add in m)-(void) application :( UIApplication *) application didReceiveLocalNotification :( UILocalNotification *) notification {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "title" message: notification. alertBody delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show]; // the number on the icon minus 1 application. applicationIconBadgeNumber-= 1 ;}


-(Void) applicationWillEnterForeground :( UIApplication *) application {// when the app is directly opened, the number on the icon is reset to application. applicationIconBadgeNumber = 0 ;}


Code added to the called class

// Push method // set local push parameters and push-(void) scheduleNotification {UILocalNotification * notification = [[UILocalNotification alloc] init]; // set NSDate * pushDate = [NSDate dateWithTimeIntervalSinceNow: 5]; if (notification! = Nil) {// set the push time (5 seconds later) notification. fireDate = pushDate; // set the time zone (this is the default time zone) notification. timeZone = [NSTimeZone defaultTimeZone]; // sets the repetition interval (0 by default, no repeated push) notification. repeatInterval = 0; // push sound (default) notification. soundName = UILocalNotificationDefaultSoundName; // push content notification. alertBody = @ "push subject content"; // digital notification displayed on the icon. applicationIconBadgeNumber = 1; // set userinfo to enable NSDictionary * info = [NSDictionary dictionaryWithObject: @ "name" forKey: @ "key"]; notification. userInfo = info; // Add push to UIApplication * app = [UIApplication sharedApplication]; [app scheduleLocalNotification: notification];}


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.