gpt4 book ai didi

ios - Apple Watch 通知操作在 iPhone 配套应用程序终止时不起作用 watch OS 5.3.2

转载 作者:行者123 更新时间:2023-11-29 13:53:01 26 4
gpt4 key购买 nike

我正在开发也支持 watch 的 iOS 应用程序以下是我的担忧。

观看操作系统 - 5.3.2 和 iOS 13.1

我在 watch 应用程序中遇到通知操作问题。当 iPhone 应用程序终止时,如果我在 watch 中收到通知,如果我点击操作,什么也不会发生。

我正在转发推送通知和用户通知操作,我正在注册用户通知。

如下

 // this I will call in iPhone app code in did finishlaunching with options.

func registerForPushNotifications(withUserInfo userInfo: [AnyHashable: Any]?) {
if #available(iOS 10.0, *) {
self.requestAuthorization(withUserInfo: userInfo)
} else {
registerUserNotificationSettings(withUserInfo: userInfo)
UIApplication.shared.registerForRemoteNotifications()
}
}

func registerUserNotificationSettings() {
let approveAction = UIMutableUserNotificationAction()
approveAction.title = NSLocalizedString("Approve", comment: "Notification approve button title")
approveAction.identifier = "approve"
approveAction.isDestructive = false
approveAction.activationMode = .background
approveAction.isAuthenticationRequired = true

let denyAction = UIMutableUserNotificationAction()
denyAction.title = NSLocalizedString("Deny", comment: "Notification deny button title")
denyAction.identifier = "deny"
denyAction.isDestructive = true
denyAction.activationMode = .background
denyAction.isAuthenticationRequired = true

let signInCategory = UIMutableUserNotificationCategory()
signInCategory.setActions([approveAction, denyAction], for: .default)
signInCategory.identifier = "pushotp"

let categories = NSSet(object: signInCategory) as? Set<UIUserNotificationCategory>

let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: categories)
DispatchQueue.main.async(execute: {
UIApplication.shared.registerUserNotificationSettings(settings)
})
}

场景

  1. 当 iPhone 应用程序处于后台并且 iPhone 被锁定并观看时在后台。如果我从服务器推送推送通知,请观看显示带有两个 Action 的通知横幅,如果我点击任何一个action ,它工作正常。

  2. 当 iPhone 应用程序被终止并且 iPhone 立即被锁定时 如果我发送pushnotification , watch 显示带有两个通知横幅 Action ,如果我点击任何一个 Action ,它工作正常。

  3. 当 iPhone 应用程序被终止且 iPhone 被锁定时,保持 watch 和 iPhone闲置一个小时就这样。然后我会激活 watch 并按下 来自服务器的通知,现在 watch 显示带有两个横幅 Action ,现在如果我点击它不起作用的 Action 。

如果你们能告诉我我必须做的正确事情是什么,那就太好了。

最佳答案

为确保在第 3 个用例中执行操作,请确保 Notification Payload 应将 contentAvailable 属性设置为 YES。这样应用程序将在后台启动。并且它会相应地更新通知用户操作。

关于ios - Apple Watch 通知操作在 iPhone 配套应用程序终止时不起作用 watch OS 5.3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58556723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com