ios - 在退出或暂停应用程序时处理推送有效载荷

标签 ios objective-c ios8 push-notification apple-push-notifications

我收到了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/

相关文章:

ios - tableViewvisibleCells swift 上缺少单元格

iphone - UINavigationController 包含一个 UITableView,然后是一个包含更多 UITableView 的 UITabBarController

ios - 构建 iOS8 扩展目标时出现重复符号

ios - UITableView 的 selectRowAtIndexPath :animated:scrollPosition: not working after reloadData in iOS 8

iphone - Core Data 同一类的两个实体

ios - 如何将 rbcollectionviewinfofolderlayout 与自定义 UICollectionViewCell 和 CollectionViewLayout 一起使用

Java RMI 服务器和 Objective C 客户端

iphone - 保存在 NSUserDefaults 中

iOS - 打开另一个应用程序警报 - 使用 Dropbox 的示例

ios - 自定义 CollectionView 布局 - 消息已发送到已释放的 NSDictionary