简体   繁体   English

如何在UNNotificationContentExtension中运行应用程序

[英]How to run application within UNNotificationContentExtension

I make an ios game. 我做一个iOS游戏。 I need to add an advanced ios 10 notification with three actions (as UNNotificationAction ). 我需要添加带有三个操作的高级ios 10通知(如UNNotificationAction )。 One of the actions has to run my game. 其中一项操作必须运行我的游戏。 I have implemented the notification, actions and UNNotificationContentExtension class with didReceive function (with UNNotificationResponse argument). 我已经实现了通知,动作和UNNotificationContentExtensiondidReceive功能(带UNNotificationResponse参数)。 Everything works good: I have received my notification with actions. 一切正常:我收到了有关操作的通知。 What I should do in didReceive function to run my game? 我应该在didReceive函数中运行我的游戏吗? My code: 我的代码:

 func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
    switch (response.actionIdentifier) {
    case "inGame":
        // run game here!!!
    case "sendAgain":
        // some logic
    case "cancel":
        // another some logic
    default:
        completion(.dismiss)
    }
}

Set activationMode of the inGame action to UIUserNotificationActivationModeForeground . 设置activationMode的的inGame动作UIUserNotificationActivationModeForeground It will cause the action to open the game when user touches it. 当用户触摸游戏时,它将导致动作打开游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除 UNNotificationContentExtension 显示的视图 - How to remove UNNotificationContentExtension displayed view 如何创建没有情节提要的UNNotificationContentExtension? - How do I create a UNNotificationContentExtension without a Storyboard? 如何将相同的UNNotificationContentExtension与不同的UNNotificationAction一起使用? - How to use same UNNotificationContentExtension with different UNNotificationAction? UNNotificationContentExtension 不显示 - UNNotificationContentExtension not displaying UNNotificationContentExtension可以处理滑动吗? - Can UNNotificationContentExtension handle swipe? 如何在后台运行应用程序? - How to run the application in the background? UNNotificationServiceExtension 和 UNNotificationContentExtension 有什么区别 - What is the difference between UNNotificationServiceExtension and UNNotificationContentExtension 使用UNNotificationContentExtension显示自定义UI以进行本地通知 - Display custom UI with UNNotificationContentExtension for local notifications 不能对UNNotificationContentExtension使用AutoLayout约束 - Can't use AutoLayout Constraints on UNNotificationContentExtension iOS UNNotificationContentExtension(富通知)什么都不显示 - iOS UNNotificationContentExtension (rich notification) display nothing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM