nsurlsession

URLSession moving slow when caching a firebase video url

China☆狼群 提交于 2020-07-23 04:56:10
问题 I initially asked this question, got the answer, and in the comments @LeoDabus said: NSData(contentsOf: url) it is not mean to use with non local resources urls He suggested I use URLSession which I did, but the response is very slow. I'm wondering am I doing something wrong. The video is 2mb if that makes any difference. Inside the the session's completionHandler I tried updating the returned data on the main queue but there was a scrolling glitch while doing that. Using DispatchQueue.global

URLSession moving slow when caching a firebase video url

雨燕双飞 提交于 2020-07-23 04:55:32
问题 I initially asked this question, got the answer, and in the comments @LeoDabus said: NSData(contentsOf: url) it is not mean to use with non local resources urls He suggested I use URLSession which I did, but the response is very slow. I'm wondering am I doing something wrong. The video is 2mb if that makes any difference. Inside the the session's completionHandler I tried updating the returned data on the main queue but there was a scrolling glitch while doing that. Using DispatchQueue.global

URLSession moving slow when caching a firebase video url

邮差的信 提交于 2020-07-23 04:54:12
问题 I initially asked this question, got the answer, and in the comments @LeoDabus said: NSData(contentsOf: url) it is not mean to use with non local resources urls He suggested I use URLSession which I did, but the response is very slow. I'm wondering am I doing something wrong. The video is 2mb if that makes any difference. Inside the the session's completionHandler I tried updating the returned data on the main queue but there was a scrolling glitch while doing that. Using DispatchQueue.global

How to cancel a URL session request

…衆ロ難τιáo~ 提交于 2020-07-18 18:14:54
问题 I am upload multiple image to server using convert image to base64 and send image in a API as a parameter. But when we call api again and again then how to stop api calling on button click. I am using below code to call API. Thanks in advance let urlPath: String = "URL" let url: URL = URL(string: urlPath)! var request1 = URLRequest(url: url) request1.httpMethod = "POST" let stringPost="imgSrc=\(image)" let data = stringPost.data(using: String.Encoding.utf8) // print("data\(data)") request1

Download in documents directory or move file async - iOS

◇◆丶佛笑我妖孽 提交于 2020-07-17 09:51:26
问题 I am building an iOS app in which the user can download different files. I am using an URLSessionDownloadTask and an URLSession to download a file asynchronously. When the download is finished, the destination folder is by default, the tmp/ directory. So, when the download ends, I need to move the temporary file to another directory. For a picture or a song, this takes only 1 second maybe even less. But when the file is a video for example, it can take up to 15 seconds. The issue To allow the

How to wait for all tasks of an NSURLSession to complete?

醉酒当歌 提交于 2020-06-16 07:48:37
问题 Why is NSURLSession operation queue empty after creating and resuming an NSURLSessionTask? Is there a way to tell if an NSURLSession has tasks pending? The goal is to wait for multiple tasks to complete, but this doesn't work: NSURLSessionUploadTask *uploadTask = [self.session uploadTaskWithStreamedRequest:request]; [uploadTask resume]; // this prints "0" NSLog(self.session.delegateQueue.operationCount) // this returns immediately instead of waiting for task to complete [self.session

Best practice to replace a synchronous NSURLConnection with NSURLSession

我是研究僧i 提交于 2020-04-30 07:38:05
问题 As NSURLConnection sendSynchronousRequest:returningResponse:error:&connectionError is set deprecated I will have to replace an Importer I wrote a long time ago. The Importer does the following: It fetches data from API-A. The data there can be on multiple pages. It uses the data from the first fetch (also multipage) to query data from API-B and merges Results from the API-B query will be merged with data from API-A I implemented this with a background-operation where I use methods for each

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

非 Y 不嫁゛ 提交于 2020-03-18 12:56:47
xmpp 项目中遇到的问题,用苹果的通信API 写一个PUT 方法,向服务器上传一张图片。遇到如题问题。 Plist 文件没有NSAppTransportSecurity属性 Dic,添加该属性,再添加二级属性NSAllowsArbitraryLoads BOOL YES 苹果文档:https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html stackOverflow:http://stackoverflow.com/questions/32631184/the-resource-could-not-be-loaded-because-the-app-transport-security-policy-requi 工具类:HTTPTool.h 1 #import <Foundation/Foundation.h> 2 3 typedef void (^HttpToolProgressBlock)(CGFloat progress); 4 typedef void (^HttpToolCompletionBlock)(NSError *error); 5 6 7 8 @interface HttpTool :

从网上DownLoad(断点下载)

匆匆过客 提交于 2020-03-07 05:04:04
方法步骤一、storyboard布局 #import "ViewController.h" @interface ViewController ()<NSURLSessionDownloadDelegate> ///显示图片的 @property (weak, nonatomic) IBOutlet UIImageView *imageView; ///显示进度的 @property (weak, nonatomic) IBOutlet UIProgressView *progressView; ///下载任务的属性 @property (nonatomic,strong)NSURLSessionDownloadTask *task; ///网络请求类 @property (nonatomic,strong)NSURLSession *session; ///发送请求类 @property (nonatomic,strong)NSURLRequest *request; ///用于保存已经下载的数据的,供继续下载使用 @property(nonatomic,strong)NSMutableData *data; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do

开发只懂 AFN ?搞定 NSURLSession 才是硬道理

空扰寡人 提交于 2020-03-06 10:46:29
由于傲娇的苹果在 iOS9 之后已经放弃了 NSURLConnection ,所以在现在的实际开发中,除了大家常见的 AFN 框架,一般使用的是 iOS7 之后推出的 NSURLSession,作为一名 iOS 开发人员,如果你只知道 AFN 框架来进行网络请求,那就只能说是 too young too simple,sometimes naive。 目录 本来想创建一个目录跳转的,好像简书不支持,只好作罢,有哪位大神知道怎么在简书支持目录跳转的,希望不吝赐教! NSURLSession 的优势 NSURLSessionTask 的子类 NSURLSessionDataTask 发送 GET 请求 NSURLSessionDataTask 发送 POST 请求 NSURLSessionDataTask 设置代理发送请求 设置代理之后的强引用问题 NSURLSessionDataTask 简单下载 NSURLSessionDownloadTask 简单下载 dataTask 和 downloadTask 下载对比 写在最后 NSURLSession 的优势 NSURLSession 支持 http2.0 协议 在处理下载任务的时候可以直接把数据下载到磁盘 支持后台下载|上传 同一个 session 发送多个请求,只需要建立一次连接(复用了TCP) 提供了全局的 session