Add startup authorization for iOS8 UILocalNotification

Source: Internet
Author: User

Add startup authorization for iOS8 UILocalNotification

 

I haven't accessed UILocalNotification for a long time. I found that I have no permission to start the notification today.
The error is as follows:

Attempting to schedule a local notification 
  
   {fire date = (null), time zone = (null), repeat interval =0, repeat count = UILocalNotificationInfiniteRepeatCount, next firea badge number but haven't received permission from the user to badgethe application
  

After reading the API, it turns out that iOS8 has added the start authorization, and the user must agree to register the notification.

Add the following code:

- (void)RegistNotificationSettings{    float sysVersion=[[UIDevice currentDevice]systemVersion].floatValue;    if (sysVersion>=8.0) {        UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;        UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:type categories:nil];        [[UIApplication sharedApplication] registerUserNotificationSettings:setting];    }}

You can call the API either before the notification is registered or when the app is started.

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{    // todo ...    [self RegistNotificationSettings];    return YES;}

Note: As long as the user has authorized the app, the app will be authorized by default even if the app is deleted and installed again.

 

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.