2013-11-27 44 views
3

當這種方法(application:didReceiveRemoteNotification:fetchCompletionHandler:)完成後,我應該如何調用completionHandler中的塊?完成處理程序從未被調用?

正如文檔所述,「實際上,您的應用程序應在下載所需數據後儘快調用處理程序塊」。

+1

@Kay尼爾森,感謝你的幫助。 – Roby

回答

6

例如:

- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler 
{ 
    // Based on the provided meta data in userInfo, load the resource from our 
    // server which corresponds to the "updated" information: 

    NSDictionary* params = ; // based on userInfo 
    [self fetchInfoWithParams:params completion:^(NSData* result, NSError* error){ 
     UIBackgroundFetchResult fetchResult; 
     if (error) { 
      fetchResult = UIBackgroundFetchResultFailed; 
     } 
     else if (result) { 
      fetchResult = UIBackgroundFetchResultNewData; 
     } 
     else { 
      // data is nil 
      fetchResult = UIBackgroundFetchResultNoData; 
     } 

     // call the handler (if any): 
     if (handler) { 
      handler(fetchResult); 
     } 
    }]; 
} 
+0

,沒關係!非常感謝你。 – Roby

+0

不錯,解決我的問題。 –

相關問題