我需要根据收到的推送通知将应用重定向到特定的 View Controller 。但是,我无法获得将调用哪个委托(delegate)方法。请指导。
下面是我到目前为止尝试过的代码。我试过 didFinishLaunchingWithOptions 但没有用。
if (launchOptions) { //launchOptions is not nil
NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
if (apsInfo) { //apsInfo is not nil
[self performSelector:@selector(notificationClickedInNotificationPanel:)
withObject:userInfo
afterDelay:1];
}
}
最佳答案
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Called when App is in Foreground // Using the data received in the notification you can call the desired view controller
completionHandler([.alert, .badge, .sound])
}
和,
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Called when App is not in Foreground // Using the data received in the notification you can call the desired view controller
completionHandler()
}
关于ios - 当应用程序处于终止模式时如何从推送通知重定向到特定的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56791700/