當這種方法(application:didReceiveRemoteNotification:fetchCompletionHandler:
)完成後,我應該如何調用completionHandler
中的塊?完成處理程序從未被調用?
正如文檔所述,「實際上,您的應用程序應在下載所需數據後儘快調用處理程序塊」。
當這種方法(application:didReceiveRemoteNotification:fetchCompletionHandler:
)完成後,我應該如何調用completionHandler
中的塊?完成處理程序從未被調用?
正如文檔所述,「實際上,您的應用程序應在下載所需數據後儘快調用處理程序塊」。
例如:
- (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);
}
}];
}
,沒關係!非常感謝你。 – Roby
不錯,解決我的問題。 –
@Kay尼爾森,感謝你的幫助。 – Roby