gpt4 book ai didi

ios - 从未调用过完成处理程序?

转载 作者:可可西里 更新时间:2023-11-01 17:07:59 24 4
gpt4 key购买 nike

当这个方法 (application:didReceiveRemoteNotification:fetchCompletionHandler:) 完成后,现在我应该如何调用 completionHandler block ?

正如文档所述“在实践中,您的应用程序应在下载所需数据后尽快调用处理程序 block 。”

最佳答案

例如:

- (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);
}
}];
}

关于ios - 从未调用过完成处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com