[英]how to launch different view controllers for different local notifications in ios 10
我在不同時間在我的應用程序中收到多個本地通知。 我想根據收到的本地通知為我的應用啟動不同的視圖控制器。 我知道didfinishlaunching和didreceive通知中的啟動選項,但是我不知道如何檢測收到的通知並根據收到的通知采取措施。即使我設法做到了,問題仍然在於我可以打開視圖來自應用程序委托的控制器,但不再附加到導航控制器,而是附加到情節提要。 怎么做? 這是我的代碼:
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let customViewController:WebViewController = storyboard.instantiateViewController(withIdentifier: "webVC") as! WebViewController
let index=Constants.instructionsData.count - 1
customViewController.url=Constants.instructionsData[index].weblink!
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = customViewController
self.window?.makeKeyAndVisible()
}
您想在iOS 10中使用通知,因此我了解您想使用UNNotification。 當您使用UNNotificationRequest時,有一個稱為標識符的參數。 您可以使用它來區分是哪個通知發送了此請求。 如果您使用“舊”通知,則只需提供選擇器,該選擇器將在收到通知時執行。
編輯:在您的代碼中,您正在更改根視圖控制器,那么您想如何使導航控制器持久? 您沒有使用segues。 嘗試:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let customViewController:WebViewController = storyboard.instantiateViewController(withIdentifier: "webVC") as! WebViewController
self.window?.rootViewController?.navigationController?.pushViewController(customViewController, animated: true)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.