我收到了Push Payload的情况都做完了,除了一种情况。
这是我的实现:
如果应用程序处于后台,非 Activity 或 Activity 状态,则可以使用此方法接收通知。
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//Received Notification when the Application is Active, InActive or in Background State.
// NOTE : I am Handling below line of code with the Appropriate Conditions using Application States in my Code.
[self handleNotificationDataWithDictionary:dictionary updateUI:YES];
}
如果应用程序被挂起或退出,那么我们可以通过didFinishLaunchingWithOptions方法接收通知有效负载,但仅当用户点击通知时才可以。
这是在主屏幕或锁定屏幕上轻按推送通知时退出或暂停和打开应用程序时接收有效负载的实现,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
[[[UIAlertView alloc] initWithTitle:@"Finish" message:@"Test" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
NSLog(@"Launched from push notification: %@", dictionary);
[self handleNotificationDataWithDictionary:dictionary updateUI:NO];
}
}
}
现在最后一个案例是,当应用程序被挂起并且用户没有使用通知中心打开应用程序时,而是通过点击应用程序图标来打开应用程序。
在测试代码时,在这种情况下我无法接收有效载荷。我在Google上搜索了很多,但没有找到关于此案例的解决方案。
根据应用程序文档,当应用程序不 Activity 时,我们只能在后台或不 Activity 模式下获得有效负载。那么如何在暂停状态下实施呢?
我确实需要帮助,请发表您的最佳答案,以便对他人也有用。
最佳答案
只需输入-(如果用户点击“应用程序图标”,则您的推送已消失)!无法检索该信息。
Official Documentation about this:
如果在运行iOS的设备上点击应用程序图标,则该应用程序调用相同的方法,但不提供有关通知的信息。
关于ios - 在退出或暂停应用程序时处理推送有效载荷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32225954/