SDm*_*try 5 deprecated xamarin.ios xamarin nsurlsession ios8
在iOS8发布之前,我下载了iOS8 SDK来观看我的应用程序是如何工作的.有时我的应用程序需要从服务器下载数据,我使用NSUrlSession.现在,当app准备下载会话时,出现下一个警告:
+backgroundSessionConfiguration: is deprecated. Please use +backgroundSessionConfigurationWithIdentifier: instead.
之后我的应用程序崩溃了下一个异常:
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)
Run Code Online (Sandbox Code Playgroud)
创建NSUrlSession的代码:
NSUrlSessionConfiguration sessionConfiguration = NSUrlSessionConfiguration.BackgroundSessionConfiguration(urlSessioinId);
NSUrlDownloadDelegate downloadDelegate = new NSUrlDownloadDelegate();
NSUrlSession downloadSession = NSUrlSession.FromConfiguration(sessionConfiguration, downloadDelegate, new NSOperationQueue());
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我在Objective-C中使用以下来解决这个错误:
NSURLSessionConfiguration *sessionConfig;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0f)
{
sessionConfig =[NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"downloads"];
}
else
{
sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:@"downloads"];
}
Run Code Online (Sandbox Code Playgroud)
这应该工作.
if(UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
configDownload = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(sessionId);
}
else
{
configDownload = NSUrlSessionConfiguration.BackgroundSessionConfiguration(sessionId);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5855 次 |
| 最近记录: |