ios - 当应用程序处于终止模式时如何从推送通知重定向到特定的 View Controller

标签 ios objective-c iphone xcode

我需要根据收到的推送通知将应用重定向到特定的 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/

相关文章:

ios - 如何使 MFMailComposeViewController 的状态栏具有白色文本(LightContent)?

ios - 如何在ios中对NSMutableArray中的时间进行排序

ios - 如何在 swift3 中播放 mp3 文件?

iphone - iOS 5 中的 iPad 方向问题

ios - 由于 GTLRServiceCompletionHandler,无法为 Google Drive REST API 运行 service.executeQuery()

ios - 如何初始化另一个 View Controller 的值

ios - SKPaymentQueue.defaultQueue().removeTransactionObserver(self) 删除和添加

ios - 将 UTC 字符串转换为 NSDate

ios - 如何使用 NSPredicate 通过多文本查询搜索文本?

ios - UITableView 中的两个不同的 UITableViewCell