如何在手表套件中显示通知,其中 iPhone 应用程序已经显示通知 [英] How to show notification in watch kit , where iPhone app is already showing the notifications

查看:22
本文介绍了如何在手表套件中显示通知,其中 iPhone 应用程序已经显示通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用可以在 iPhone 中显示通知.现在我试图在 WatchKit 或 iWatch 中显示相同的通知.那么我是否需要重新复制我在 Watchkit Extension 中的 iPhone 应用程序的 ViewController 和 AppDelegate 中已经完成的所有功能,或者是否有一些通用的接口来通知手表显示通知,我只需要提供 UI.

I have an app which shows notification in iPhone. Now I am trying to show the same notification in WatchKit or in iWatch. So do I need to recopy all the functionalities I already did in ViewController and AppDelegate of iPhone app in Watchkit Extension or is there some common interface to notify the watch to show the notification, only UI I need to provide.

推荐答案

iOS 将决定向 Apple Watch 或 iPhone 发送通知.

iOS will decide to send notification to apple watch or to iPhone.

如果您的 iPhone 处于活动状态,则通知将发送到 iPhone.如果您的 iPhone 被锁定,Apple Watch 将收到通知.

If your iPhone is active then notification will come to iPhone. If your iPhone is locked then notification will come to Apple Watch.

您在添加 watchkit 应用程序目标时是否勾选了包括通知场景"?

Did you have checked "Include Notification Scene" while adding target of watchkit app?

如果是,那么您可以在故事板中看到通知类和 WKUserNotificationInterface 静态接口.

If yes then you can see notification class and WKUserNotificationInterface static interface in your storyboard.

您还可以在动态界面自定义通知屏幕.

You can also customize notification screen at dynamic interface.

如果要处理通知,请在屏幕中实现以下方法,该方法将在 Apple Watch 中点击通知后显示.

If you want to handle notification then implement below method in screen which will display after click on notification in apple watch.

override func handleActionWithIdentifier(identifier: String?,
    forRemoteNotification remoteNotification: [NSObject : AnyObject])
{

}

请看这个链接:https://developer.apple.com/library/watchos/documentation/General/Conceptual/WatchKitProgrammingGuide/CustomzingthePushNotificationInterface.html

这篇关于如何在手表套件中显示通知,其中 iPhone 应用程序已经显示通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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