How to perform a GET-request using MKNetworkKit in a newsstand app that's being started by a content-available notification

StackOverflow https://stackoverflow.com/questions/13124602

Frage

My newsstand-app can be launched via a content-available push notification. When this happens the list of issues should be retrieved an a zip file containing the latest issue should be downloaded.

I'm having trouble retrieving the list of issues. This problem only occurs when the app is started via a content-available push notification. When starting the app manually everything works fine.

This piece of code downloads the issuelist:

-(MKNetworkOperation*)getIssueList:(void(^)(NSArray *issues, BOOL cacheResponse))completionBlock
                             onError:(MKNKErrorBlock) errorBlock{
    MKNetworkOperation *op = [self operationWithPath:@"list/"
                                              params:nil
                                          httpMethod:@"GET"];
    NSLog(@"in getissuelist");

    [op onCompletion:^(MKNetworkOperation *completedOperation)
     {
         NSLog(@"in getissuelist on completion");
         BOOL cachedResponse = NO;
         if([completedOperation isCachedResponse]) {
             cachedResponse = YES;
         }

         NSArray *issueDicts = [completedOperation responseJSON];
         completionBlock(issueDicts, cachedResponse);

     }onError:^(NSError* error) {
         NSLog(@"in getissuelist on error");
         errorBlock(error);
     }];

    [self enqueueOperation:op];

    NSLog(@"in getissuelist return op");
    return op;
}

This is the console output when the app is started via the notification

Oct 29 16:06:42 murzofoon newsstand[2373] <Warning>: start download latest
Oct 29 16:06:42 murzofoon newsstand[2373] <Warning>: in getissuelist
Oct 29 16:06:42 murzofoon newsstand[2373] <Warning>: in getissuelist return op

So the operation is enqueued, but the onCompletion (and onError) block is not being called.

When I manually launch the app after receiving the notification, the onCompletion block is called.

Oct 29 16:06:54 murzofoon newsstand[2373] <Warning>: in getissuelist on completion

It seems that the MKNetworkOperation is not processed until I manually start the app. I'd like to have the onCompletionblock be called even when I didn't manually start the app. How can this problem be resolved?

War es hilfreich?

Lösung

It turns out that the problem had nothing to do with MKNetworkKit. I forgot to buy some background time to finish these tasks.

When the networkfunctions are called after a beginBackgroundTaskWithExpirationHandler-call they work just fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top