rem*_*3my 3 apple-push-notifications ios swift tvos
嗨,我是tvOS的新手。我有一个为APNS注册的电视应用程序。
但是当我推送通知时,我无法收到通知。我正在获取设备令牌,但没有通知。
当我尝试使用移动设备时,我会收到通知,但在tvOS中却不是,为什么?
我该如何解决..?
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if granted == true
{
print("Allow")
UIApplication.shared.registerForRemoteNotifications()
}
else
{
print("Don't Allow")
}
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print("DEVICE TOKEN = \(deviceTokenString)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print(error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print(userInfo)
}
Run Code Online (Sandbox Code Playgroud)
tvOS仅支持两种通知:badges和content-available。因此,您需要将这两种类型之一发送到APNS。这些类型的任何通知仅会更改“应用程序图标”上的徽章编号。当您打开应用程序时,只有最新的通知会传递到您的应用程序。没有像iOS上那样直观的通知呈现方式,它来自WWDC 2016 / Session 206 / tvOS的呈现方式,从21:20开始观看
更新:在tvOS 11上出现了Silent notifications,它将唤醒应用程序并允许在后台刷新内容
| 归档时间: |
|
| 查看次数: |
3163 次 |
| 最近记录: |