我正在尝试实现后台推送通知处理,但是我遇到了一个问题,即无法确定用户是从推送通知打开应用程序还是从图标打开应用程序。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
//************************************************************
// I only want this called if the user opened from swiping the push notification.
// Otherwise I just want to update the local model
//************************************************************
if(applicationState != UIApplicationStateActive) {
MPOOpenViewController *openVc = [[MPOOpenViewController alloc] init];
[self.navigationController pushViewController:openVc animated:NO];
} else {
///Update local model
}
completionHandler(UIBackgroundFetchResultNewData);
}
使用这段代码,无论用户如何打开应用程序,应用程序都会打开到MPOOpenViewController视图控制器。我该如何使其仅在从通知滑动打开应用程序时推送视图控制器?
与相同的代码一起,在iOS 6上运行良好,但使用新的iOS 7方法后,它的行为不符合我的要求。
编辑:我现在正在尝试在iOS 7上运行该应用程序,并且我们不支持iOS 7之前的任何版本。我在方法的iOS 6版本中使用了完全相同的代码(没有完成处理程序),并且它的行为符合我的期望。您可以滑动通知,然后将调用此方法。如果您从图标打开,则永远不会调用该方法。