Tar*_*rek 5 uiwebview push-notification ios swift onesignal
我正在处理我原来的 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])
Run Code Online (Sandbox Code Playgroud)
尝试在 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"]))"
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1295 次 |
| 最近记录: |