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.