码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8 UILocalNotification 增加启动授权

时间:2015-11-09 17:14:18      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:

原来iOS8增加了启动授权,需要用户同意下才能注册通知。

添加如下代码:

- (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];
    }
}

你可以在注册通知之前调用,也可以在app启动时候调用

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    // todo ...

    [self RegistNotificationSettings];
    return YES;
}

 

注意:只要用户对app授权过了,以后即使删除再次安装,也默认为授权了。

iOS8 UILocalNotification 增加启动授权

标签:

原文地址:http://www.cnblogs.com/crash-wu/p/4950415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!