zoukankan      html  css  js  c++  java
  • 注册推送的方式

     //注册推送
        if (@available(iOS 10.0, *)) {
            // iOS10及以上注册远程通知的方法
            UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
            // 必须写代理,不然无法监听通知的接收与点击
            center.delegate = self;
            [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
                if (granted) {
                    // 点击允许
                    NSLog(@"注册成功");
                    [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
                        NSLog(@"%@", settings);
                    }];
                } else {
                    // 点击不允许
                    NSLog(@"注册失败");
                }
            }];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        } else if (@available(iOS 8.0, *)) {
            // iOS8-iOS10注册远程通知的方法
            UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
            UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        } else {
            // 在iOS8之前注册远程通知的方法,如果项目中要支持iOS8之前的版本,必须要写此方法
            UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
            
        }
        
  • 相关阅读:
    serialVersionUID作用
    为什么要使用SLF4J而不是Log4J
    认识Log4j
    Java解析xml文件四种方式
    数据结构之R进制转换
    栈的压入、弹出序列
    中间件学习之RMI+JDBC远端数据库的访问
    Linux程序设计综合训练之简易Web服务器
    Html5笔记之小结
    PhoneGap + Dreamweaver 5.5 无法在模拟器中打开的问题
  • 原文地址:https://www.cnblogs.com/gaoxiaoniu/p/11346930.html
Copyright © 2011-2022 走看看