相关疑难解决方法(0)

didReceiveRemoteNotification:fetchCompletionHandler:从图标vs推送通知打开

我正在尝试实现后台推送通知处理,但是我在确定用户是否从发送的推送通知中打开应用程序时遇到了问题,而不是从图标打开它.

- (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);
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,无论用户如何打开应用程序,应用程序都会打开MPOOpenViewController.我怎样才能使视图控制器只有在他们通过刷通知打开应用程序时才会被推送?

使用相同的代码,这适用于iOS 6,但使用新的iOS 7方法,它的行为并不像我想要的那样.

编辑:我正在尝试在iOS 7上运行应用程序,我们不支持iOS 7之前的任何版本.我在方法的iOS 6版本中使用了相同的确切代码(没有完成处理程序)并且它表现得很好我希望它的方式.你要刷通知,这将被调用.如果从图标打开,则永远不会调用该方法.

push-notification apple-push-notifications uiapplicationdelegate ios ios7

50
推荐指数
3
解决办法
4万
查看次数

远程通知方法调用两次

application:didReceiveRemoteNotification:fetchCompletionHandler:在我的应用程序委托中实现了响应推送通知.

当应用程序在后台时收到通知时,会立即调用此方法,并在完成后获取新数据并执行完成块.全部按照文档.但是,如果我点击通知警报,则会再次调用此方法,从而导致另一个网络调用和UI更新.我希望每个推送通知都会调用一次此方法,而不是一次收到,再次执行操作.

其他人如何实施这种方法?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [self loadSomeResource:^(NSData *data,NSError *error){
        if (error) {
            completionHandler(UIBackgroundFetchResultFailed);
        }
        else if (data){
            completionHandler(UIBackgroundFetchResultNewData);
        }
        else {
            completionHandler(UIBackgroundFetchResultNoData);
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

objective-c push-notification ios ios7

13
推荐指数
1
解决办法
6242
查看次数