nsurlsession

How to do multipart/form-data post request with Swift?

被刻印的时光 ゝ 提交于 2019-12-01 11:50:16
let Url = String(format: "http://url/ios.php") guard let serviceUrl = URL(string: Url) else { return } let parameterDictionary :[String:String] = ["Episodes" : "http://url/anime/07-ghost.html"] var request = URLRequest(url: serviceUrl) request.httpMethod = "POST" request.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type") request.httpBody = NSKeyedArchiver.archivedData(withRootObject: parameterDictionary) let session = URLSession.shared session.dataTask(with: request) { (data, response, error) in if let response = response { print(response) } if let data = data { do { let json

Uploading file using NSURLSessionUploadTask to PHP server

假如想象 提交于 2019-12-01 11:41:51
问题 I have a video upload system in an iOS app using NSURLSessionUploadTask . The video file is saved to an NSURL so I am using the following code in my upload method: request.HTTPMethod = @"POST"; [request addValue:@"file" forHTTPHeaderField:@"fileName"]; // Create upload task NSURLSessionUploadTask *task = [session uploadTaskWithRequest:request fromFile:filePath completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if(!error) { // handle success } else { // handle error }

How return data from an HTTP request in Swift/Objective C

我们两清 提交于 2019-12-01 11:38:19
I'm trying to use Coinbase's API to get information about my online bitcoin wallet, and I'm trying to use Swift's NSURLSession object to do so. Perhaps I'm missing something obvious in the Apple docs, but after reading through the information about NSURLSession and NSURLSessionTask I still do not understand how to make an HTTP request and then return the body of the response so that the body can persist throughout the life of my app. As of now I only see the ability to use completion blocks which return void, or delegates which either return void themselves or use completion blocks which also

NSURLSession memory leak

孤人 提交于 2019-12-01 11:10:29
Even after invalidate a NSURLSession, running a profile using Instruments, some classes (probably privates) called TubeManager, HTTPConnectionCache and HTTPConnectionCacheDictionary still alive in memory. Code snippet to reproduce: NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]; NSURLSessionDataTask* sessionDataTask = [session dataTaskWithRequest:request completionHandler:^

NSURLSession didCompleteWithError:gets called with NSError is nil

痴心易碎 提交于 2019-12-01 08:50:20
Scenario is taking the app to background and foreground multiple times when its uploading is in progress,didCompleteWithError: method is called while taking app to foreground with error parameter is null. Probabilty is 1/3. How do i find out what went wrong as error parameter does not give anything. The problem is that didCompleteWithError report only client side error, otherwise is nil. iOS doc said: "Server errors are not reported through the error parameter. The only errors your delegate receives through the error parameter are client-side errors , such as being unable to resolve the

NSURLSession memory leak

巧了我就是萌 提交于 2019-12-01 08:35:46
问题 Even after invalidate a NSURLSession, running a profile using Instruments, some classes (probably privates) called TubeManager, HTTPConnectionCache and HTTPConnectionCacheDictionary still alive in memory. Code snippet to reproduce: NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]

NSURLSession didCompleteWithError:gets called with NSError is nil

*爱你&永不变心* 提交于 2019-12-01 06:46:05
问题 Scenario is taking the app to background and foreground multiple times when its uploading is in progress,didCompleteWithError: method is called while taking app to foreground with error parameter is null. Probabilty is 1/3. How do i find out what went wrong as error parameter does not give anything. 回答1: The problem is that didCompleteWithError report only client side error, otherwise is nil. iOS doc said: "Server errors are not reported through the error parameter. The only errors your

iOS开发中常用的单例

社会主义新天地 提交于 2019-12-01 05:30:45
1、UIApplication(应用程序实例) 获取方式:[UIApplication sharedApplication] 详细:http://www.cnblogs.com/hissia/p/5678518.html 2、NSNotificationCenter(消息中心) 获取方式:[NSNotificationCenter defaultCenter] 常用的通知模式 3、NSFileManager(文件管理) 获取方式:[NSFileManager defaultManager] 4、NSUserDefaults(偏好设置) 获取方式:[NSUserDefaults standardUserDefaults] 详细:http://www.cnblogs.com/hissia/p/5642405.html 5、NSURLCache(请求缓存) 获取方式:[NSURLCache sharedURLCache] 6、NSHTTPCookieStorage(应用程序cookies池) 获取方式:[NSHTTPCookieStorage sharedHTTPCookieStorage] 7、NSURLSession(发送请求时候用的) 获取方式:[NSURLSession sharedSession] 8、UIMenuController(弹出的 菜单 可以选择,复制,剪切

Getting server data for the Apple Watch

空扰寡人 提交于 2019-12-01 04:53:23
I am wondering how to go about designing a watchOS app that depends on getting the latest feed from a server. Would you need to use application context and just have the iPhone push it over in the background using the WatchConnectivity framework or would you use NSURLSession on the Apple Watch itself? Keep in mind this is for watchOS 2. You can use NSURLSession to handle your request. So your request would be native on your watchn. But note that your watch is there to show simple Content to the user. 来源: https://stackoverflow.com/questions/31465130/getting-server-data-for-the-apple-watch

NSURLSession详解

冷暖自知 提交于 2019-12-01 04:43:20
< 1 > NSURLSession 简介 : { NSURLSession 是 iOS 7.0 之后推出的网络解决方案 ! 用于替代 NSURLConnection, 针对下载 / 上传等复杂的网络操作提供了专门的解决方案 ! NSURLSession 使用更加简单 / 方便 ! } < 2 > NSURLSession 中新增的内容 : { 1 > 全局的 NSURLSession 对象 : 所有的网络会话都由一个 NSURLSession 对象发起 , 实例化一个 NSURLSession 对象有两种方法 : { * 1 对于简单的 , 不需要监听网络请求过程的网络会话来说 , 使用系统提供的 , 全局的 NSURLSession 单利对象 : NSURLSession *session = [NSURLSession sharedSession]; * 2 如果需要监听网络进度 , 需要自定义一个 NSURLSession 对象 , 并且设置代理 ! 这时还需要一个 NSURLSessionConfiguration, 可以设置全局的网络访问属性 . NSURLSessionConfiguration *cfg = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session =