我正在尝试NSURLSessionDataTask
在后台获取时在我的应用程序委托中运行一个,但是尽管我从完成处理程序中获取了有效数据,但应用程序并未触发该方法。这是我的代码
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSURLSession *serverConfigure = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSessionConfiguration *serverSession = [NSURLSession sessionWithConfiguration:serverConfigure delegate:self delegateQueue:nil];
NSURLSessionDataTask *serverDownload = [serverSession dataTaskWithURL:[NSURL URLWithString:@"myurl"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSArray *downloadedData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[self handleData:downloadedData];
}];
[serverDownload resume];
}