![](/img/trans.png)
[英]Why NSURLConnection didReceiveData not be called in background location update
[英]NSUrlConnection not called via background fetch
-(void)application:(UIApplication )application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"In performFetchWithCompletionHandler");
DownloadAlerts alertDownload = [[DownloadAlerts alloc]init];
[alertDownload getAlertsOnLocUpdate];
completionHandler(UIBackgroundFetchResultNewData); // We will add content here soon.
}
[NSURLConnection sendAsynchronousRequest:request
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error) {
if ([data length] >0 && error == nil) {
NSLog(@"Hello01");
} else if ([data length] == 0 && error == nil) {
NSLog(@"Hello02");
} else if (error != nil) {
NSLog(@"Hello03");
}
}];
我正在通過appdelegate.h
的performFetchWithCompletionHandler
調用的函數中執行上述代碼。 當我通過后台抓取啟動應用程序時,如果執行塊,則3個都不執行。 我該如何實施? 我需要通過后台提取下載數據。 請幫助... NSUrlSession
也不起作用..
您是否嘗試發送同步請求? 我認為您的performFetchWithCompletionHandler方法在NSURLConnection收到響應之前完成。 順便說一句,您確定是否調用performFetchWithCompletionHandler嗎? 也許您需要為此設置功能?
需要調用“ completionHandler(UIBackgroundFetchResultNewData);” 收到數據后,將其作為參數傳遞到“ getAlertsOnLocUpdate”方法中,並在從服務器(在URLConnection的completedHandler中)收到答復后調用它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.