问题描述
我是 tvOS 的新手.我有一个已注册 APNS 的电视应用.
但是当我推送通知时,我无法收到通知.我收到了设备令牌,但没有收到通知.
当我尝试使用移动设备时,我收到了通知,但在 tvOS 中却没有,为什么会这样......?
我该如何解决这个问题..?
let center = UNUserNotificationCenter.current()center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in如果授予 == 真{打印(允许")UIApplication.shared.registerForRemoteNotifications()}别的{打印(不允许")}}func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})打印(设备令牌 = \(设备令牌字符串)")}func 应用程序(_ 应用程序:UIApplication,didFailToRegisterForRemoteNotificationsWithError 错误:错误){打印(错误)}func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {打印(用户信息)}
tvOS 仅支持两种类型的通知:badges
和 content-available
.所以你需要将这两种类型之一发送到APNS.这些类型的通知中的任何一种都只会更改应用程序图标上的徽章编号.当您打开应用程序时,只有最新的通知才会发送到您的应用程序.没有像在 iOS 上那样的视觉呈现通知它在
更新:在 tvOS 11 上出现了Silent notification
,它可以唤醒应用程序并允许在后台刷新内容
Hi i am a newbie to tvOS. I have an TV application which is registered for APNS.
But while i push a notification i am not able to get the notifications.i am getting the device token but not the notification.
While i try with the Mobile Devices i am getting the notifications,But not in the tvOS why is it so...?
How can i solve this..?
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)
}
tvOS supports only 2 types of notifications: badges
and content-available
. So you need to send one of these two types to APNS. Any of these types notification only changes badge number on App Icon. And only the lastest notification will be delivered to your application when you open the app. There is no visual presentation of notification as it was on iOSHow it looks see on presentation from WWDC 2016/Session 206/tvOS, start watching from 21:20
UPDATE:On tvOS 11 appeared Silent notifications
which wakes the application up and allow to refresh content in background
这篇关于tvOS 中的 Apple 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!