0
我使用OneSignal
和Swift 3
來做應用程序。我得到了推動。如何在單擊通知時在OneSignal
中使用WebView
顯示特定ViewController
。在推送"link"
字段的附加數據時,我獲得了鏈接,但無法在我的WebView
中顯示此鏈接。如何在OneSignal Swift中顯示特定的ViewController
我嘗試使用全局變量tempURL
將URL從additional data
。但它不起作用。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
OneSignal.initWithLaunchOptions(launchOptions, appId: "MYID", handleNotificationAction: { (result) in
let payload = result?.notification.payload
print("This is Payload \(payload)")
var fullMessage = payload?.title
let messageTitle = "OneSignal Example"
if (result?.action.actionID) != nil {
let additionalData = payload?.additionalData
let url = additionalData?["link"] as! String?
tempURL = url!
fullMessage = fullMessage! + "\nPressed ButtonId:\(url)"
}
let alertController = UIAlertController(title: messageTitle, message: fullMessage, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default)
alertController.addAction(okAction)
alertController.show(alertController, sender: nil)
})
return true
}
試圖表明:
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
let aViewController = ViewController()
aViewController.loadAddressURL(url: tempURL)
UIApplication.shared.keyWindow?.rootViewController?.present(aViewController, animated: true, completion:nil)
}
我有錯誤:在您的方式
fatal error: unexpectedly found nil while unwrapping an Optional value
謝謝!它發生了。 – Zhanserik
歡迎編碼... – emresancaktar