gpt4 book ai didi

ios - 快速请求通知权限(iOS 7)

转载 作者:搜寻专家 更新时间:2023-11-01 06:09:57 30 4
gpt4 key购买 nike

我如何在 iOs 8 和 iOs7 中请求权限。我试过这个:

UIApplication.sharedApplication().registerForRemoteNotificationTypes(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)

但它不起作用。

这是我的代码,仅适用于 iOS 8:

  if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) {
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Sound, categories: nil))
}

else {

}

最佳答案

最近更改了一些语法。这对我有用。

if(UIApplication.instancesRespondToSelector(#selector(UIApplication.registerUserNotificationSettings(_:)))) {
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes:[.Badge , .Sound , .Alert], categories: nil))
UIApplication.sharedApplication().registerForRemoteNotifications()
}

关于ios - 快速请求通知权限(iOS 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27823152/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com