我正在开发一个非常庞大的应用程序,它已经有远程推送通知。此通知还包括 Facebook 通知,它们在 iPhone 和 iPad 上显示得非常好,问题是现在我需要在 Apple Watch 上显示相同的通知,但我不知道该怎么做。
这是我的 AppDelegate,我在其中声明远程通知:
func handleNotification(_ application: UIApplication,userInfo: [AnyHashable: Any]) {
if let notification = userInfo["notification"] as? NSDictionary {
let notiicationInfo = notification
let notiicationAPS = userInfo["aps"] as! NSDictionary
let type = notiicationInfo["type"] as! String!
let name = notiicationInfo["name"] as! String!
let value = notiicationInfo["value"] as! String!
let message = notiicationAPS["alert"] as! String!
NSLog("notiicationInfo \(notiicationInfo)")
var promotions : [[String:Any]]? = []
promotions!.append(["id": name as AnyObject, "name":message as AnyObject, "creative":"" as AnyObject, "position":"1" as AnyObject])
if let customBar = self.window!.rootViewController as? CustomBarViewController {
if (application.applicationState == UIApplicationState.background || application.applicationState == UIApplicationState.inactive)
{
let dataLayer: TAGDataLayer = TAGManager.instance().dataLayer
dataLayer.push(["ecommerce": ""])
dataLayer.push(["ecommerce": NSNull()])
dataLayer.push(["event": "promotionClick", "ecommerce": [ "promoClick" : ["promotions": promotions!] ] ] )
let delay = 2.0 * Double(NSEC_PER_SEC)
let time = DispatchTime.now() + Double(Int64(delay)) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: time, execute: {
customBar.handleNotification(type!,name:name!,value:value!)
})
}
else {
let dataLayer: TAGDataLayer = TAGManager.instance().dataLayer
dataLayer.push(["ecommerce": ""])
dataLayer.push(["ecommerce": NSNull()])
dataLayer.push(["ecommerce": ["promoView":["promotions": promotions!] ],"event":"ecommerce" ])
_ = AlertController.presentViewController(message!,
icon:UIImage(named:"alerta_hello.png"),
titleButton: NSLocalizedString("general.continue",comment:""),
action: {() in
let dataLayer: TAGDataLayer = TAGManager.instance().dataLayer
dataLayer.push(["ecommerce": ""])
dataLayer.push(["ecommerce": NSNull()])
dataLayer.push(["event": "promotionClick", "ecommerce": [ "promoClick" : ["promotions": promotions!] ] ] )
if let controller = UIApplication.shared.keyWindow?.rootViewController {
if controller.presentedViewController != nil {
if let tutController = controller.presentedViewController as? ImageDisplayCollectionViewController {
tutController.closeModal()
}
}
}
customBar.handleNotification(type!,name:name!,value:value!)
}
)
}
}
UIApplication.shared.applicationIconBadgeNumber = 0
UIApplication.shared.cancelAllLocalNotifications()
}
}
有谁知道我必须在代码中添加什么才能在 Apple Watch 上显示此通知?我已经添加了 Watch Os Target,但我不知道在该设备上的何处声明此远程通知。