tvOS中的Apple Push通知 [英] Apple Push Notifications in tvOS

查看:91
本文介绍了tvOS中的Apple Push通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是tvOS的新手.我有一个为APNS注册的电视应用程序.

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.

当我尝试使用移动设备时,我会收到通知,但在tvOS中却没有,为什么……?

While i try with the Mobile Devices i am getting the notifications,But not in the tvOS why is it so...?

我该如何解决..?

   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仅支持两种通知类型:badgescontent-available.因此,您需要将这两种类型之一发送到APNS.这些类型的通知中的任何一种都只会更改应用程序图标"上的徽章编号.当您打开应用程序时,只有最新的通知会传递到您的应用程序.没有像iOS那样直观的通知形式 从 WWDC 2016/Session 206/tvOS的演示中看,它从21点开始观看: 20

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 iOS How it looks see on presentation from WWDC 2016/Session 206/tvOS, start watching from 21:20

更新: 在tvOS 11上出现了Silent notifications,它可以唤醒应用程序并允许在后台刷新内容

UPDATE: On tvOS 11 appeared Silent notifications which wakes the application up and allow to refresh content in background

WWDC 2017观看时间为7:50

这篇关于tvOS中的Apple Push通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆