簡體   English   中英

NSUrlConnection未通過后台提取調用

[英]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.hperformFetchWithCompletionHandler調用的函數中執行上述代碼。 當我通過后台抓取啟動應用程序時,如果執行塊,則3個都不執行。 我該如何實施? 我需要通過后台提取下載數據。 請幫助... NSUrlSession也不起作用..

您是否嘗試發送同步請求? 我認為您的performFetchWithCompletionHandler方法在NSURLConnection收到響應之前完成。 順便說一句,您確定是否調用performFetchWithCompletionHandler嗎? 也許您需要為此設置功能?

需要調用“ completionHandler(UIBackgroundFetchResultNewData);” 收到數據后,將其作為參數傳遞到“ getAlertsOnLocUpdate”方法中,並在從服務器(在URLConnection的completedHandler中)收到答復后調用它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM