nsurlsession

iOS网络请求 添加全局代理 NSURLSessionConfiguration 解决方案

拥有回忆 提交于 2020-01-13 18:10:11
1、最近做项目、文件存储服务器是用的亚马逊的、如果直接访问、下载其资源速度很慢、所以需要在网络请求的时候添加一个代理、加速网络访问 2、代理服务器是一个HTTPS 的一个服务器 3、思路、解决方案、利用运行时机制(添加分类NSURLSession+Change)针对 NSURLSession 初始化添加代理对所有的网络请求进行拦截处理 #import "NSURLSession+Change.h" @implementation NSURLSession (Change) +(void)load{ Method oldMethod = class_getClassMethod(self, @selector(sessionWithConfiguration:delegate:delegateQueue:)); Method newMethod = class_getClassMethod(self, @selector(newSessionWithConfiguration:delegate:NSURLSessiondelegateQueue:)); Method oldMethod1 = class_getClassMethod(self, @selector(sessionWithConfiguration:)); Method newMethod1 = class

Why does connecting back to an iOS background NSURLSession take too long waiting on a lock, crashing the app?

拟墨画扇 提交于 2020-01-12 18:51:48
问题 Why would connecting with an NSURLSession through its configuration take so long that it would crash the app on start up: 'failed to launch in time'? I've seen similar crash dumps in many iOS apps including NY Times iOS app and Evernote app. [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:queue] Here's the stack trace: Thread 0: 0 libsystem_kernel.dylib 0x3afb7aa0 semaphore_wait_trap + 8 1 libdispatch.dylib 0x3af04d3d _dispatch_semaphore_wait_slow + 173 2

HTTP digest authentication fail due to wrong nonce-count in iOS 10

点点圈 提交于 2020-01-11 03:57:13
问题 HTTP digest authentication no longer works in our app since iOS 10 due to wrong nonce-count in Authorization: Digest header generated by NSURLSession. The same code works in iOS 9, but fail to auth in iOS 10 Create a POST request with NSURLRequest Fire it with NSURLSession Handle NSURLAuthenticationMethodHTTPDigest in urlSession(_:didReceive:completionHandler:) delegate The server responds with a 401 and qop="auth" string as expected The app requests again with the Authorization: Digest

iOS 7 background upload and POST requests

大城市里の小女人 提交于 2020-01-11 03:45:07
问题 I need to upload files in the background with other HTTP POST requests before and after each upload. Previously I was using beginBackgroundTaskWithExpirationHandler which was working perfectly till iOS 6 but from IOS 7 it is restricted for approx 180 seconds only which is a concern. I have read the documents regarding NSURLSession were in we have Background transfer service. But the problem with this is it only allows upload and download in background. It doesn't allow me to make POST request

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1

安稳与你 提交于 2020-01-10 00:39:33
问题 I am using iOS 9 as target & using Xcode 7.1, tried everything as my level best for all the solutions of ATS but didn't work. Below is the following error description coming at console. If any suggestion comes I will be obliged. Some of the key things here are - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) Error excluding Main.db from backup Error Domain=NSCocoaErrorDomain Code=4 "The file “Main.db” doesn’t exist." UserInfo={NSURL=file:///Users/Raj/Library

NSURLSessionDataTask dataTaskWithURL completion handler not getting called

旧城冷巷雨未停 提交于 2020-01-09 05:17:30
问题 I have been learning Objective C lately, and I decided to try connections. Everything was great with NSURLConnection, until I discovered it was outdated, and tried to work with NSURLSession. I am trying a very simple example, but can't seem to get my app to run the code inside the completion block. Here is the code used: NSURL * url = [NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather?q=London,uk"]; NSLog(@"2"); NSURLSessionConfiguration *defaultConfigObject =

How to add a proxy to NSURLSession in Xamarin.iOS?

馋奶兔 提交于 2020-01-06 21:47:12
问题 I need to load the content of the webview using a proxy. I have this code (Objective-C): NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; configuration.connectionProxyDictionary = @{ (NSString *)kCFStreamPropertyHTTPProxyHost: [proxyURL host], (NSString *)kCFStreamPropertyHTTPProxyPort: [proxyURL port] }; The following Xamarin code doesn't work, ConnectionProxyDictionary is set but application doesn't use this settings: var configuration =

How to add a proxy to NSURLSession in Xamarin.iOS?

前提是你 提交于 2020-01-06 21:46:24
问题 I need to load the content of the webview using a proxy. I have this code (Objective-C): NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; configuration.connectionProxyDictionary = @{ (NSString *)kCFStreamPropertyHTTPProxyHost: [proxyURL host], (NSString *)kCFStreamPropertyHTTPProxyPort: [proxyURL port] }; The following Xamarin code doesn't work, ConnectionProxyDictionary is set but application doesn't use this settings: var configuration =

NSURLSession resume from crash

情到浓时终转凉″ 提交于 2020-01-06 17:26:46
问题 Has anyone got any tips on how to reconnect to a download in a NSURLSession after a crash. If my app crashes, I believe the download continues on the device anyway, and then when my app relaunches I can use the same sessionID in: NSURLSessionConfiguration.backgroundSessionConfiguration(sessionID) However, am I then supposed to call 'session.getTasksWithCompletionHandler' to see if there are any tasks? The docs aren't clear. My UI has a download progress bar for each file download, so ideally

iOS: trigger NSURLErrorServerCertificateUntrusted instead of NSURLErrorCancelled when failing the AuthenticationChallenge

左心房为你撑大大i 提交于 2020-01-06 07:59:44
问题 I'm handling the server trust authentication challenge in a custom way (comparing the public key from the server trust with a hashed local version) through the urlSessionDelegate, similarly to how it is done here: How do I accept a self-signed SSL certificate using iOS 7's NSURLSession and its family of delegate methods for development purposes? As described in the documentation, I need to cancel the challenge if I want to fail the server trust authentication myself. When doing this, my data