当这个方法(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);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6320 次 |
| 最近记录: |