我正在尝试使用iOS 10 UserNotifications框架做一些非常基本的事情:在选择默认操作时打开特定的ViewController。我已经完成了许多教程,但他们都专注于自定义类别和操作,并且他们也没有真正显示在确定操作后启动特定ViewController的代码(这只是留下作为注释或打印语句)。
我想做两件事之一,取决于可能的事情:
我的AppDelegate将自己设置为UNUserNotificationCenterDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Make this object responsible for handling notification events.
UNUserNotificationCenter.current().delegate = self
return true
}
然后我想使用以下内容来覆盖选择的ViewController:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
switch response.actionIdentifier {
case UNNotificationDismissActionIdentifier:
// Notification was dismissed. Do nothing.
completionHandler()
case UNNotificationDefaultActionIdentifier:
// App opened from notification.
// ??? Select ViewController to show based on information found in the notification ???
completionHandler()
default:
completionHandler()
}
}