1
在xcode 8.3中使用swift3,這是一個webview應用程序。如何在前臺收到通知時彈出消息框?
下面是我在ViewController.swift函數來處理URL從推送通知收到
func redirectTo(url: String) {
let request = URLRequest(url: URL(string: url)!)
MyApp.loadRequest(request)
}
下面是我在AppDelegate.swift功能當我的應用程序在後臺運行處理didReceiveRemoteNotification
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let pushUrl = userInfo[AnyHashable("url")] as? String {
viewController?.redirectTo(url: pushUrl)
}
}
,當我點擊它時,它會將我的應用程序重定向到從通知中收到的網址。
然而,當在前臺運行我的應用程序,它會直接重定向我的WebView不撒手網址。
我知道這是因爲我每次收到通知時,它會調用redirectTo功能的loadRequest然後。
我的問題是,我如何添加一個消息框,有兩個按鈕,我的應用程序運行時,在forefround和收到通知它會要求用戶重定向或取消?
只需在兩個選項中添加一個警報提示,並有兩個選項ok並取消,在ok點擊時重定向到url代碼。延遲後顯示警報。希望它可以幫助你 – Chandan
@Chandan我完全是一個新的迅速。我會嘗試一下。真的很感激。 – Dreams