IOS8: backgroundSessionConfiguration deprecated

Before iOS8 was released, I downloaded the iOS8 SDK to see how my application would work. Sometimes my application needs to download data from the server, and I use NSUrlSession for it. And now, when the application preparing the session for download, the following warning appears:

+backgroundSessionConfiguration: is deprecated. Please use +backgroundSessionConfigurationWithIdentifier: instead +backgroundSessionConfiguration: is deprecated. Please use +backgroundSessionConfigurationWithIdentifier: instead .

After that, the application will shut down with the following exception:

 Unable to cast object of type 'MonoTouch.Foundation.NSUrlSessionTask' (Objective-C type: '__NSCFBackgroundDownloadTask') to type 'MonoTouch.Foundation.NSUrlSessionDownloadTask'. Additional information: Selector: URLSession:downloadTask:didFinishDownloadingToURL: Method: Microsoft.Synchronization.ClientServices.NSUrlDownloadDelegate:DidFinishDownloading (MonoTouch.Foundation.NSUrlSession,MonoTouch.Foundation.NSUrlSessionDownloadTask,MonoTouch.Foundation.NSUrl) 

Code for creating NSUrlSession:

 NSUrlSessionConfiguration sessionConfiguration = NSUrlSessionConfiguration.BackgroundSessionConfiguration(urlSessioinId); NSUrlDownloadDelegate downloadDelegate = new NSUrlDownloadDelegate(); NSUrlSession downloadSession = NSUrlSession.FromConfiguration(sessionConfiguration, downloadDelegate, new NSOperationQueue()); 

Thanks for any help!

+5
source share
2 answers

That should work.

 if(UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { configDownload = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(sessionId); } else { configDownload = NSUrlSessionConfiguration.BackgroundSessionConfiguration(sessionId); } 
+8
source

I have the following solution to this error in Objective-C:

 NSURLSessionConfiguration *sessionConfig; if ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0f) { sessionConfig =[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"downloads"]; } else { sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:@"downloads"]; } 
+9
source

Source: https://habr.com/ru/post/1200403/


All Articles