gpt4 book ai didi

ios - 如何防止 IOS Swift 上的 OneSignal 在处理通知时打开 WebView

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:38 26 4
gpt4 key购买 nike

我在我原来的 webview 中处理 lunchUrl 但问题是当我把kOSSettingsKeyInAppLaunchURL

[true] 它在我原来的 webview 上打开新的 webview

[false] 它在 safary 中打开链接

let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
let payload = result?.notification.payload
if let additionalData = result!.notification.payload!.additionalData {
// DEEP LINK and open url in RedViewController
centerViewController.receivedURL = payload!.launchURL as! String!

self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = centerViewController
self.window?.makeKeyAndVisible()
}
}

OneSignal.initWithLaunchOptions(launchOptions, appId: "*****", handleNotificationReceived: { (notification) in
}, handleNotificationAction: notificationOpenedBlock , settings: [kOSSettingsKeyAutoPrompt : true, kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.notification.rawValue, kOSSettingsKeyInAppLaunchURL: true])

最佳答案

尝试在 Appdelegate 中使用此代码:

let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
// This block gets called when the user reacts to a notification received
let payload: OSNotificationPayload = result!.notification.payload

/// Check response message click notification in here
var fullMessage = payload.body
self.window?.rootViewController = UINavigationController(rootViewController: ViewController())

}

if payload.additionalData != nil {
if payload.title != nil {
let messageTitle = payload.title
let additional = payload.additionalData["recive_id"] as! String
print("tes aditional data: \(additional)")
print("Message Title = \(messageTitle!)") //proses notif klik "3" Goto target
if messageTitle == "id" {
self.window?.rootViewController = UINavigationController(rootViewController: ViewController())
}
}

let additionalData = payload.additionalData
if additionalData?["actionSelected"] != nil {
fullMessage = fullMessage! + "\nPressed ButtonID: \(String(describing: additionalData!["actionSelected"]))"
}
}
}

关于ios - 如何防止 IOS Swift 上的 OneSignal 在处理通知时打开 WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48824101/

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