zoukankan      html  css  js  c++  java
  • 【转】IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送

     在IOS7中设置applicationIconBadgeNumber不会有什么问题,但是直接在IOS8中设置applicationIconBadgeNumber会报错

    因为在IOS8中要想设置applicationIconBadgeNumber,需要用户的授权,在IOS8中,需要加上下面的代码:

    1
    2
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    但是这两句如果是在IOS7的系统中运行的话就会报错,所以需要先判断IOS的版本,完整代码如下:
    1
    2
    3
    4
    5
    6
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
         
    if (version >= 8.0) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }

    如果是注册消息推送的话,需要这样写:

    1
    2
    3
    4
    5
    6
    7
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
     
    if (version >= 8.0) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [application registerForRemoteNotifications];
    }
     
    from:http://my.oschina.net/are1OfBlog/blog/393165
  • 相关阅读:
    centos7安装kde桌面
    centos7安装NVIDIA驱动
    15日报
    11日报
    14日报
    奖励加分
    课程建议
    13日报
    12日报
    每日总结1213
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/5113902.html
Copyright © 2011-2022 走看看