在 iOS 上将推送通知作为后台应用程序获取
Get push notification as background app on iOS
我正在做某个申请。
有这些功能
1 此应用程序有推送通知。
2 此应用程序在激活时可以存储推送通知日志。
3 此应用程序可以在不活动时存储推送通知日志。
1,2 对我来说还可以。 1是正常的,2是推送通知回调完成的。
然而 3...?
我想 Android 后台作业正常运行并收到通知。
但是 iOS 是不可能的吗?
当应用程序未激活时,您可以使用 didFinishLaunchingWithOptions 委托方法处理推送通知:
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (localNotif) {
NSString *json = [localNotif valueForKey:@"data"];
// Parse your string to dictionary
}
除了前面的回答:关于didFinishLaunchingWithOptions
。
这仅在通过单击 notification/push 消息 window 启动程序时有效。但是,如果您直接 运行 应用程序,通过单击应用程序图标,即使 notification/push 消息到达,您也不会在 launchOptions
中收到任何有关推送消息的数据。
那么关于第3段:只有用户点击推送消息才能知道它window/bar。
我正在做某个申请。
有这些功能
1 此应用程序有推送通知。
2 此应用程序在激活时可以存储推送通知日志。
3 此应用程序可以在不活动时存储推送通知日志。
1,2 对我来说还可以。 1是正常的,2是推送通知回调完成的。
然而 3...?
我想 Android 后台作业正常运行并收到通知。
但是 iOS 是不可能的吗?
当应用程序未激活时,您可以使用 didFinishLaunchingWithOptions 委托方法处理推送通知:
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (localNotif) {
NSString *json = [localNotif valueForKey:@"data"];
// Parse your string to dictionary
}
除了前面的回答:关于didFinishLaunchingWithOptions
。
这仅在通过单击 notification/push 消息 window 启动程序时有效。但是,如果您直接 运行 应用程序,通过单击应用程序图标,即使 notification/push 消息到达,您也不会在 launchOptions
中收到任何有关推送消息的数据。
那么关于第3段:只有用户点击推送消息才能知道它window/bar。