2016-11-21 46 views
0

我使用OneSignalSwift 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

回答

1

首先你不能傳遞數據。你應該用StoryboardID實例化ViewController。我解釋瞭如何用this link.

使用它,如果你是相當肯定的是,你的additionalData不是零,你可以通過你的數據與StoryboardID

+0

謝謝!它發生了。 – Zhanserik

+0

歡迎編碼... – emresancaktar

相關問題