• haven't received permission


    iOS8里对权限的控制更为严格了,就是标题中的permission

    以前下给icon弄个数字提醒什么的,直接一句简单的:

    [UIApplication sharedApplication].applicationIconBadgeNumber=20;

    就搞定了,现在这么直接iOS不干了,没有反应了,还给你一个警告

    Attempting to badge the application icon but haven't received permission from the user to badge the application

    大概意思就是给应用程序添加数字提醒(badge),但是你没有这个权限。

    用户通知设置

    既然没有权限那咱就加权限呗。其实类似这种给应用程序加数字提醒的功能也是一中通知(Notification),有一个类叫做UIUserNotificationSettings,从名字就能看出是一个用户界面的通知设置相关的类,这哥们里面就一个静态方法

    + (instancetype)settingsForTypes:(UIUserNotificationType)types

                          categories:(NSSet *)categories; // instances of UIUserNotificationCategory

    在UIApplication里也有它的身影@interface UIApplication (UIUserNotificationSettings),乖乖人家可直接成了UIApplication的扩展了!具体使用如下

    UIUserNotificationSettings *settting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settting];
        
        [UIApplication sharedApplication].applicationIconBadgeNumber=20;
    View Code

    写到这里,icon上就出现了badge上设置的数字了。细看下settingsForTypes里的传参类型

    typedef NS_OPTIONS(NSUInteger, UIUserNotificationType) {

        UIUserNotificationTypeNone    = 0,      // the application may not present any UI upon a notification being received

        UIUserNotificationTypeBadge   = 1 << 0, // the application may badge its icon upon a notification being received

        UIUserNotificationTypeSound   = 1 << 1, // the application may play a sound upon a notification being received

        UIUserNotificationTypeAlert   = 1 << 2, // the application may display an alert upon a notification being received

    } NS_ENUM_AVAILABLE_IOS(8_0);

    可见这是8.0的新玩意,看样子在一个更重要的场合:推送里面也得注册相应的UIUserNotificationType才能正常工作喽……

  • 相关阅读:
    HDU 3537 Daizhenyang's Coin(博弈,翻硬币)
    【转】博弈-翻硬币游戏
    QRCode.js:使用 JavaScript 生成二维码
    3种高效的Tags标签系统数据库设计方案分享
    CI框架+Umeditor上传图片配置信息
    【军哥谈CI框架】之CI中集成百度UEditor
    【ci框架基础】之部署百度编辑器
    CI框架中集成CKEditor编辑器的教程
    如何将文本编辑器嵌入框架--以Umeditor&CodeIgniter框架为例
    ****CI和UEditor集成
  • 原文地址:https://www.cnblogs.com/luseike/p/4359826.html
Copyright © 2020-2023  润新知