我需要从收到的推送通知中将应用程序重定向到特定的视图控制器。但是,我无法获得将调用哪个委托方法。请指导。
以下是我到目前为止尝试过的代码。我已经在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/