草庐IT

NSUrlSession

全部标签

ios - 应用程序传输安全 : NSURLSession/NSURLConnection HTTP load failed

我有这个代码:funcloginWithBasicAuth()->Void{letusernameText=username.textletpasswordText=password.textletcredentialData="\(usernameText):\(passwordText)".dataUsingEncoding(NSUTF8StringEncoding)letbase64Credentials=credentialData?.base64EncodedStringWithOptions([])letheaders=["Authorization":"HTTPBasic

swift - NSURLSession 初始化错误

我正在尝试像这样创建一个NSURLSession:letsession=NSURLSession(configuration:NSURLSessionConfiguration.defaultSessionConfiguration(),delegate:self,delegateQueue:NSOperationQueue.mainQueue())所以我可以做一些下载之类的,但我一直收到这个错误:Cannotfindinitializerfortype'NSURLSession'thatacceptsanargumentlistoftype'(configuration:NSURLS

ios - 带有 NSURLSession 的 Swift 中的 HTTP 请求

我正尝试使用NSURLSession在iOS应用程序中使用Swift发出HTTP请求,但XCode抛出错误。我一直在搜索整个stackoverflow和网络,我的代码与人们建议的非常相似,但由于某种原因它不起作用。我在XCode6.0.1(6A317)上。varsession=NSURLSession.sharedSession().dataTaskWithURL(NSURL(url),completionHandler:{(data,response,error)->Voidinprintln("Done")})session.resume()错误指向上面的第一行:“Extraarg

ios - 如何正确清理 Swift 中的 NSURLSession

我正在使用以下代码在类的初始化上创建一个NSURLSession:dispatch_once(&Static.token){[unownedself]inletconfiguration=NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(CONSTANTS.BackgroundSessionUploadIdentifier)Static.session=NSURLSession(configuration:configuration,delegate:self,delegateQueue:nil

ios - 请求超时 NSURLSession

你好,我使用下面的代码向服务器发送请求。如何在此函数中添加超时staticfuncpostToServer(url:String,varparams:Dictionary,completionHandler:(NSDictionary?,String?)->Void)->NSURLSessionTask{letrequest=NSMutableURLRequest(URL:NSURL(string:url)!)letsession=NSURLSession.sharedSession()request.HTTPMethod="POST"if(params["data"]!="get")

ios - Swift xcode 6 label.text 在 NSURLSession 中没有改变

这是一个简单的测试应用程序,用于演示如何从网络中提取数据。其中有一个由按钮操作触发的NSURLSession。importUIKitclassViewController:UIViewController{@IBOutletweakvarcity:UITextField!@IBOutletweakvarmessage:UILabel!@IBActionfuncbuttonPressed(sender:AnyObject){varurlString="http://www.weather-forecast.com/locations/"+city.text.stringByReplaci

ios - 如何从 NSURLSession 获取字符串形式的数据?

我使用的API以简洁的格式提供数据-如何将其作为String获取?我可以打印它,但将其保存为字符串似乎不起作用。我特别想使用NSURLSession任务中的数据更新UI元素。leturl=NSURL(string:apiCall)lettask=NSURLSession.sharedSession().dataTaskWithURL(url!){(data,response,error)in//Iwanttoreplacethislinebelowwithsomethingtosaveittoastring.println(NSString(data:data,encoding:NSU

ios - NSURLSession 的 NSURLCache 没有按预期工作

我在使用NSURLCache时看到了奇怪的行为,并用尽了所有选项但在这里发布......所以这里是:我正在尝试将NSURLCache与NSURLSession结合使用作为底层缓存机制。使用Charles和简单的println()我观察到无论我做什么,我的应用程序都会继续返回服务器并重新请求以前的请求。我验证了我的服务器一致地发送以下header:Cache-Control:public,max-age=31449600Content-Length:74289Content-Type:image/jpegETag:"abcdf"Expires:Sun,03Jan201620:58:01G

ios - 操作扩展 - 多个 NSURLSession

我正在尝试通过ActionExtension从照片应用程序上传图像。我使用NSURLSession在后台上传它。这是我使用的代码。varconfigName="com.myapp.uploadImage"varconfig=NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(configName)config.sharedContainerIdentifier="group.myApp.sample"varsession=NSURLSession(configuration:config)lett

ios - 如何使用 2 个不同的 NSURLSession (iOS Swift) 获取 2 个不同的 webview

我想创建一个具有2个Webview的iOS应用程序(1个商店,1个已登录的商店)如果我在一个webview中登录,另一个webview包含相同的cookie,并且第一个webview也会登录。我需要第一个拥有自己的session(cookie)!我的计划是保护已保存的登录Touch-ID,并免费提供人人都可以使用的WebView。我目前正在搜索2个半小时并尝试了以下内容:letrequest=NSMutableURLRequest(URL:NSURL(string:"https://www.my-url.com")!)request.setValue("",forHTTPHeaderF