gpt4 book ai didi

xamarin.ios - iOS8:backgroundSessionConfiguration 已弃用

转载 作者:行者123 更新时间:2023-12-04 16:31:14 28 4
gpt4 key购买 nike

在 iOS8 发布之前,我下载了 iOS8 SDK 以观察我的应用程序将如何工作。有时我的应用程序需要从服务器下载数据,我为此使用 NSUrlSession。现在,当应用程序准备下载 session 时,会出现下一个警告:
+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)

创建 NSUrlSession 的代码:
NSUrlSessionConfiguration sessionConfiguration = NSUrlSessionConfiguration.BackgroundSessionConfiguration(urlSessioinId);
NSUrlDownloadDelegate downloadDelegate = new NSUrlDownloadDelegate();
NSUrlSession downloadSession = NSUrlSession.FromConfiguration(sessionConfiguration, downloadDelegate, new NSOperationQueue());

谢谢你的帮助!

最佳答案

我使用以下方法来解决 Objective-C 中的这个错误:

NSURLSessionConfiguration *sessionConfig;

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

关于xamarin.ios - iOS8:backgroundSessionConfiguration 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325130/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com