iPhone 启动选项

标签 iphone push-notification apple-push-notifications

我在推送通知后没有收到任何启动选项;这是我的代码,但似乎没有 NSLogs 在调试区域中打印。

UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (localNotif) {
    NSString *itemName = [localNotif.userInfo objectForKey:@"aps"];
    NSLog(@"Custom: %@", itemName);
} else {
    NSLog(@"//////////////////////////");

}

当我打开应用程序(通过按推送通知上的 View )时,它会转到 didReceiveRemoteNotification 脚本,我不确定这是否意味着会发生..

感谢您的阅读。

最佳答案

您的应用程序通过多个路径接收推送通知,具体取决于您的应用程序收到通知时的状态。

如果您的应用未启动(甚至没有在后台暂停),则 launchOptions 将包含通知负载(键 UIApplicationLaunchOptionsRemoteNotificationKey)。

如果它已经在后台运行或暂停,应用程序将通过应用程序委托(delegate)中的 application:didReceiveRemoteNotification: 接收通知。

本地通知的过程相同(application:didFinishLaunchingWithOptions: 和 application:didReceiveLocalNotification: 中的 UIApplicationLaunchOptionsLocalNotificationKey)

关于iPhone 启动选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5456134/

相关文章:

push-notification - react native : Call a function from tapping a Push Notification?

ios - 来自 Azure 通知中心的 Xamarin.iOS 推送通知

ios - 最初从 firebase 获取无效的推送 token ,最后获取有效的推送 token

iphone - 使用分组 TableView 时 IOS 键盘关闭

ios - 如何在 iOS 推送通知后在除一个 View 之外的任何地方显示 UIAlertView

ios - 发送推送通知而不访问 UDID

iphone - SSL证书错误: certificate_unknown

ios - 呈现 Modal 全屏 SwiftUI

iphone - 如何在 objective-c 中取消调度 NSTimer

iphone - iPhone SDK 中的 Tell-A-Friend 形式