zoukankan      html  css  js  c++  java
  • iOS8 UILocalNotification 增加启动授权

    原来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授权过了,以后即使删除再次安装,也默认为授权了。

  • 相关阅读:
    洛谷P2751 工序安排Job Processing
    UVA 1613 K度图染色
    线段树+扫描线
    分组背包
    洛谷P5506 封锁
    洛谷P2574 XOR的艺术
    List.Sort
    Dict.Count
    Convert.ToString(null) => null
    Convert 输入字符串的格式不正确
  • 原文地址:https://www.cnblogs.com/crash-wu/p/4950415.html
Copyright © 2011-2022 走看看