首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS推送通知

iOS推送通知
EN

Stack Overflow用户
提问于 2016-12-05 09:31:24
回答 1查看 280关注 0票数 0

我使用APNS,它在iOS 9上工作得很好。随着iOS10上新的push API的更改,我无法注册push通知,所以我插入了接下来的更改:

  1. 在“目标功能”选项卡中启用推送通知。
  2. 在didFinishLaunchingWithOptions中,我们检查OS版本并按以下方式注册: 如果(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) { //ios 10 NSLog *center = UNUserNotificationCenter currentNotificationCenter;center.delegate = self;[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound UNAuthorizationOptionAlert UNAuthorizationOptionAlert UNAuthorizationOptionBadge)完全处理程序:^(BOOL授予,NSError * _Nullable错误){ if( ! error ){ [UIApplication sharedApplication registerForRemoteNotifications];NSLog(@"iOS 10成功推送通知寄存器");}];}{ // iOS 8-9通知[UIApplication sharedApplication settingsForTypes:(UIUserNotificationTypeSound AC.26 UIUserNotificationTypeAlert UIUserNotificationTypeAlert UIUserNotificationTypeBadge)类别:nil];[UIApplication sharedApplication registerForRemoteNotifications];NSLog(@"iOS 9成功推送通知寄存器");}

通过这些更改,我成功地在iOS 9和iOS 10中执行了注册,但我遇到了两个问题:

  1. 一旦我在目标功能选项卡中启用了推送通知,推送通知就会停止在iOS 9上工作,尽管注册已经成功完成。
  2. push在iOS 10上根本不起作用,尽管注册已经成功完成。

请记住,如果我关闭目标功能选项卡中的推送通知(使用相同的代码),推送返回到iOS 9上,但我不能在iOS 10上注册APNS。

EN

回答 1

Stack Overflow用户

发布于 2016-12-05 13:58:12

代码语言:javascript
复制
    if #available(iOS 8.0, *) {
        let settings: UIUserNotificationSettings = UIUserNotificationSettings (types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    }else {
        let types: UIRemoteNotificationType = [.alert, .badge, .sound]
        application.registerForRemoteNotifications(matching: types)
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40971020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档