دنبال کننده ها

۱۳۹۶ تیر ۱۳, سه‌شنبه

ios - How to popup a message box when receive a notification on foreground?

[ad_1]



Using swift3 with xcode 8.3 and this is a webview app.



Below is my function in ViewController.swift to handle url received from push notification



func redirectTo(url: String) 
let request = URLRequest(url: URL(string: url)!)
MyApp.loadRequest(request)



Below is my function in AppDelegate.swift to handle 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)




When my app running on background, it will redirect my app to url received from notification when I click on it.



However, when my app running on foreground, it will directly redirect my webview to url without doing nothing.



I know this is because every time I received a notification , it will call redirectTo function and then loadRequest.



My question is , how can I add a message box with two button, when my app running on forefround and receive a notification it will ask user to redirect or cancel ?




[ad_2]

لینک منبع