收到通知时点击打开本地通知 - iOS - Swift
Open Local Notification on tap when Notification received - iOS - Swift
我实现了我的本地通知并且应用程序显示了通知。我有回复、取消、打开应用等通知操作
如果应用程序在后台并且一旦用户点击 "Open App" 我想打开应用程序
请告诉我如何处理这个问题,即在用户点击 notificationAction 时,如果它处于 background/inactive 状态
,则打开应用程序
截至目前,在我的 didReceive 响应中,我有以下代码..但它没有打开应用程序。请指教
if UIApplication.shared.canOpenURL(appHookUpURL! as URL)
{
UIApplication.sharedApplication.openURL(appHookUpURL! as URL)
}
您只需将操作配置为:
let openAppAction = UNNotificationAction(identifier: "YOUR_IDENTIFIER", title: "Open App", options: .foreground)
将 options
设置为 .foreground
。
UNNotificationActionOptions - foreground
The action causes the app to launch in the foreground.
When the user selects an action containing this option, the system
brings the app to the foreground, asking the user to unlock the device
as needed. Use this option for actions that require the user to
interact further with your app. Do not use this option simply to bring
your app to the foreground.
无需调用UIApplication.sharedApplication.openURL
。
我实现了我的本地通知并且应用程序显示了通知。我有回复、取消、打开应用等通知操作
如果应用程序在后台并且一旦用户点击 "Open App" 我想打开应用程序
请告诉我如何处理这个问题,即在用户点击 notificationAction 时,如果它处于 background/inactive 状态
,则打开应用程序截至目前,在我的 didReceive 响应中,我有以下代码..但它没有打开应用程序。请指教
if UIApplication.shared.canOpenURL(appHookUpURL! as URL)
{
UIApplication.sharedApplication.openURL(appHookUpURL! as URL)
}
您只需将操作配置为:
let openAppAction = UNNotificationAction(identifier: "YOUR_IDENTIFIER", title: "Open App", options: .foreground)
将 options
设置为 .foreground
。
UNNotificationActionOptions - foreground
The action causes the app to launch in the foreground.
When the user selects an action containing this option, the system brings the app to the foreground, asking the user to unlock the device as needed. Use this option for actions that require the user to interact further with your app. Do not use this option simply to bring your app to the foreground.
无需调用UIApplication.sharedApplication.openURL
。