草庐IT

NSUrlSession

全部标签

ios - NSURLSession 返回元组的问题

我在一个网站上做了一个请求,我想返回3个字符串,但我遇到了这个问题:Tupletypes'(StringLiteralConvertible,StringLiteralConvertible,StringLiteralConvertible)'and'()'haveadifferentnumberofelements(3vs.0)这就是我的代码的样子:funcdownloadContent()->(title:String,message:String,buttonText:String)?{leturl=NSURL(string:websitePath)!letsession=NSU

ios - Swift NSURLSession 真的真的真的很慢

我正在使用NSURLSession在我的应用程序中是这样的:funcwsQAshowTag(tag:Int,completion:([AnyObject]!->Void)){letrequestString=NSString(format:“URL”,tag)asStringleturl:NSURL!=NSURL(string:requestString)lettask=NSURLSession.sharedSession().dataTaskWithURL(url,completionHandler:{data,response,errorindo{letresult=tryNSJS

swift - 从 NSURLSession 下载中获取文件名

我正在使用NSURLSession下载文件。某些网站(如亚马逊)不在URL中使用文件名(如:http://server/file.php?id=22)。我怎样才能得到这些文件名?没有名称的示例URL:https://odesk-prod-att.s3.amazonaws.com/...oCtjM%3D我正在使用这样的功能:funcURLSession(session:NSURLSession,downloadTask:NSURLSessionDownloadTask,didFinishDownloadingToURLlocation:NSURL){print("Downloadfini

ios - Swift UIImage 转换为 PDF

在我的应用程序中,必须从iPadGallery出售UIImage并将其转换为PDF并保存在服务器端。我可以选择图像并将其发送到服务器端,但后端显示pdf为空(空数据)我还在我的控制台中看到警告/错误:发现扩展时遇到的[发现]错误:ErrorDomain=PlugInKitCode=13"querycancelled"UserInfo={NSLocalizedDescription=querycancelled}我哪里错了?提前致谢!我试过的代码//OpensgallerytoselectImagefuncclickImage(){letimage=UIImagePickerContro

ios - 在 iOS 上的 Swift 中从短 URL 获取完整 URL

给定一个短URLhttps://itun.es/us/JB7h_,如何将其扩展为完整URL?例如https://music.apple.com/us/album/blackstar/1059043043 最佳答案 扩展extensionURL{funcgetExpandedURL()asyncthrows->Result{varrequest=URLRequest(url:self)request.httpMethod="HEAD"let(_,response)=tryawaitURLSession.shared.data(for:

ios - 在控制台中记录 NSURLSession 请求

是否可以将NSURLSession发送的请求记录到控制台?我在身份验证方面遇到问题,如果无法查看请求,我将无法调试 最佳答案 这些方法将以干净的方式打印HTTP请求和响应:classfunclog(request:URLRequest){leturlString=request.url?.absoluteString??""letcomponents=NSURLComponents(string:urlString)letmethod=request.httpMethod!=nil?"\(request.httpMethod!)":

ios - 为 Alamofire 全局设置超时间隔

我在整个项目中都使用Alamofire,如下所示:Alamofire.request("http://my.api.com",method:.get,parameters:["some":"thing"],encoding:URLEncoding.default,headers:myHeaders)有没有一种快速的方法可以像上面那样为我的所有请求设置超时?我已经尝试了以下但没有运气Alamofire.SessionManager.default.session.configuration.timeoutIntervalForRequest=10Alamofire.SessionMana

xcode - 使用 NSURLSession 处理异步模式

我正在使用Xcode7和Swift2,但我的问题不一定是特定于代码的,我很乐意接受各种帮助。在我的应用程序中,我有一个收藏夹列表。由于APITOS,我不能存储任何数据,所以我只保留一个stub,当用户打开应用程序时我可以用它来查找。由于没有批处理方法,我还必须一个一个地查找每个最喜欢的。现在我有这样的东西:self.api.loadFavorite(id,completion:{(event,errorMessage)->VoidiniferrorMessage==""{ifletrc=self.refreshControl{dispatch_async(dispatch_get_ma

ios - 多个 NSURLSession 加载 Json

我想加载两个NSURLSession。问题是在第二个NSURLSession中,我需要一个由第一个NSURLSession给出的key。这就是我所做的,但它似乎不起作用!NSURLSession.sharedSession().dataTaskWithURL(url!){(data,response,error)indo{letjson=tryNSJSONSerialization.JSONObjectWithData(data!,options:.MutableContainers)//fetchingitemsfromjson...foriteminitems{//Iextract

ios - swift :URLSessionConfiguration

我有FirstViewController,带有要在SecondTableViewController中移动的按钮。在SecondTableViewController中,我有单元格,如果我点击单元格下载开始。问题:如果我从FirstViewController移入SecondTableViewController开始下载并在FirstViewController中返回,然后移入SecondTableViewController我明白了:AbackgroundURLSessionwithidentifiercom.example.DownloadTaskExample.backgrou