0

我希望推送通知让我的应用程序从服务器获取内容。我使用 RESTKit。我正在尝试实现application:didReceiveRemoteNotification:fetchCompletionHandler:然后执行我的 REST 请求(这是一个块)。我可以在日志中看到请求已发送,但没有答案。我想这是因为应用程序在后台。我该如何解决?

4

1 回答 1

0

我用块解决了这个问题。我的代码是:

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
     NSString *type = [userInfo valueForKey:@"type"];
     if ([type isEqualToString:@"message"]) {
         [self.viewController fetchFromServerWithSuccesBlock:^{
             NSLog(@"succes block");
             completionHandler(UIBackgroundFetchResultNewData);
         } withFailBlock:^{
             NSLog(@"fail block");
             completionHandler(UIBackgroundFetchResultNewData);
         }];
     }
}

这样,completionHandler当我的请求块完成时就会调用它。

于 2014-12-25T11:05:56.890 回答