com.apple.mobilesafari 无法启动,因为设备被锁定

我想打开一个带有可操作通知按钮的 URL,我的代码在我的设备未锁定时工作,但是当设备被锁定并且我想单击操作按钮时,应用程序崩溃并出现此错误消息

NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace) for reason: Locked ("com.apple.mobilesafari cannot be launched because the device is locked") 

我的代码如下:

func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
    
    let defaultsSettings = UserDefaults.standard
    let customToken =  defaultsSettings.value(forKey: "customToken")
    
    let userInfo = response.notification.request.content.userInfo
    
    // Perform the task associated with the action.
    switch response.actionIdentifier {
    
    case "open":
        if (userInfo["type"] != nil){
            if(userInfo["type"] as! String == "campfireOpened"){
                let title = userInfo["title"] as! String
                if let url = URL(string: "https://www.reloadium.com/news?search=\(title.replacingOccurrences(of: "#",with: "."))&customToken=\(customToken ?? "No Token")"){
                    UIApplication.shared.open(url,options: [:],completionHandler: nil)
                }
                break
            }
            else if (userInfo["type"] as! String == "conversationOpened"){
                let title = userInfo["title"] as! String
                if let url = URL(string: "https://www.reloadium.com/news?search=\(title.replacingOccurrences(of: "#",completionHandler: nil)
                }
                break
            }
            else if (userInfo["type"] as! String == "message"){
                let conversationId = userInfo["conversationId"] as! String
                if let url = URL(string: "https://www.reloadium.com/conversations?setactiveConversation=\(conversationId)&customToken=\(customToken ?? "No Token")"){
                    UIApplication.shared.open(url,completionHandler: nil)
                }
                break
            }
        }
        else {
            print("Type is null")
            print("User Info",userInfo)
            break
        }
    case "cancel":
        print("cancel button")
        break
            
    default:
        break
        
    }
    print(userInfo)
    // Always call the completion handler when done.
    completionHandler()
  }
}

当设备被锁定时,您是否有任何想法打开带有可操作通知的 URL?

a15116337758 回答:com.apple.mobilesafari 无法启动,因为设备被锁定

要打开带有可操作通知按钮的 URL,当设备被锁定时,您需要像这样声明 .foreground 时设置 UNNotificationAction 选项:

   let open = UNNotificationAction(
        identifier: "open",title: "Open",options: .foreground
    )
本文链接:https://www.f2er.com/747642.html

大家都在问