0

I'm working with an app utilizing RestKit (which may or may not be relevant to the issue I'm having) in which the app wakes up for a few seconds after certain intervals and makes a managedObjectRequestOperation to a server. This works perfectly all day long, but typically between about 1am and 7am when my device is sitting charging having not been used in a few hours the request gets sent but I'm not registering any sort of response.

The requests don't seem to be timing out or any other similar errors, my logs print that I'm sending a request and then nothing happens at all, no response, no error... Does the phone go into some sort of coma-mode overnight? My device is an iPhone 5 running iOS7.

EDIT:

What I was basically doing is sending a request to a server and updating core data with the results, which then updates a tableView. My original implementation basically sent an NSNotification to the app, which tells a tableview to send a request and update itself according to the results, similar to this:

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshData" object:nil];

    completionHandler(UIBackgroundFetchResultNewData);
}

When really it should be doing this:

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [RefreshDataWithCompletionHandler:(void (^)(id result))completionHandler {
         // handle updating the data here based on the result of the request to the server
         ......

         // then call the completion handler here
         completionHandler(UIBackgroundFetchResultNewData); 
   }];
}

Is that a more accurate representation of the correct steps?

4

1 回答 1

2

从讨论中,听起来问题在于如何发出请求以及与完成处理程序的关系。当performFetchWithCompletionHandler:被调用时,应立即启动请求(发布通知对此很好,因为它内联运行)。请求应在 30 秒内完成,然后应在处理接收到的数据后调用提供的完成块(在 RestKit 成功块中也是如此)。

如果您过早调用完成块,则应用程序将在发送请求之前(它是异步的)或在收到任何响应之前终止(它将被忽略)。

于 2014-01-28T22:31:38.133 回答