nsurlsession

NSURLSession delegate vs. completionHandler

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've always used completion handlers. With NSURLConnection and now with NSURLSession . It's led to my code being really untidy, especially I have request within request within request. I wanted to try using delegates in NSURLSession to implement something I've done untidily with NSURLConnection . So I created a NSURLSession , and created a dataTask : NSURLSessionDataTask *dataTask = [overallSession dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if(error == nil) { NSString * text = [[NSString

NSURLSession causing EXC_BAD_ACCESS

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've noticed that implementing NSURLSessionDataDelegate and starting a task will very occasionally throw an EXC_BAD_ACCESS. The actual calling method that gives the error seems to vary but always comes from CFNetwork . For the most part, the calling method comes from NSURLSession delegate_dataTask:didReceiveData:completionHandler . I've attached two crash logs with different callers below. I've also attached my implementation of NSURLSessionDataDelegate . Unfortunately I cannot reliably reproduce the error, so I don't have an example script

iOS 9.3 : An SSL error has occurred and a secure connection to the server cannot be made

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting following error with self signed certificate Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made. while testing web-services for one of my demo app with iOS 9.3 XCode 7.3 Swift 2.2 Alamofire 3.3.0 and Local server : https://filename.hostname.net Note: before assuming its Duplicate, I would request please read it all the way,even same i have reported to apple dev forums Using Alamofire Library func testAlamofireGETRequest() -> Void { Alamofire.request(.GET,

What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

断了今生、忘了曾经 提交于 2019-12-03 01:21:53
In latest apple introduce new NSURLSession in replace of NSURLConnection , so in there are different task , so what is the difference between NSURLSessionDataTask , NSURLSessionDownloadTask ? and in which scenario use NSURLSessionTask and where NSURLSessionDownloadTask ? NSURLSessionDataTask : Data tasks exchange data using NSData. NSURLSessionDataTask is not supported in Background Sessions. Data tasks send and receive data using NSData objects. Data tasks are intended for short, often interactive requests from your app to a server. Data tasks can return data to your app one piece at a time

NSURLSessionDataTask dataTaskWithURL completion handler not getting called

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 = [NSURLSessionConfiguration defaultSessionConfiguration]; NSLog(

iOS: NSURLSession category methods not being found at runtime

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wanted to create a category on NSURLSession. The app compiles ok, but when I attempt to call the category methods I get -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0 :0: error: -[NSURLSession_UPnPTests testCategory] : -[__NSCFURLSession doSomething]: unrecognized selector sent to instance 0xbf6b0f0 Very strange, here is a test class I built to show the issue. The category on the NSString works fine, but the category on NSURLSession fails to find the method at runtime. I suspect this is something internal

NSURLSession: uploading assets with background transfer

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What's the best approach to use background transfer to upload assets from gallery? Seems like uploadTaskWithRequest:fromData: doesn't work with NSURLSession created with backgroundSessionConfiguration since it causes an exception: "Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file". Judging from the exception description background transfer shouldn't work with streamed upload tasks too. Fair enough. uploadTaskWithRequest:fromFile: is the first thing that comes to

iOS 7 NSURLSession Download multiple files in Background

假如想象 提交于 2019-12-03 00:40:16
I want to download a List of files using NSUrlSession. I have a variable for counting the successful downloads @property (nonatomic) int downloadsSuccessfulCounter; . While the files are being downloaded I disable the Download Button . When the counter is equal to the download list size, I enable the button again and set the counter to 0. I do this in the method: -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { ... [[NSOperationQueue mainQueue] addOperationWithBlock:^ { downloadsSuccessfulCounter++; if

HTTP Request in swift not working

纵饮孤独 提交于 2019-12-02 20:58:08
I'm trying to learn about working with APIs in Swift. As a good first test, I figured I'd hit the itunes API and just return some search results. I'm in playground using the following code. I don't get any errors, but my println isn't outputting anything. Anyone know what's wrong? Thanks! import UIKit import XCPlayground XCPSetExecutionShouldContinueIndefinitely() let url = NSURL(string: "https://itunes.apple.com/lookup?id=909253") let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in println(NSString(data: data, encoding: NSUTF8StringEncoding)) } task

How to resume NSURLSession download process after app force-quit and app relaunch?

牧云@^-^@ 提交于 2019-12-02 20:44:57
I have implemented NSURLSession for downloading fairly large files from our servers. Now as long as I'm working in foreground or background and go back to the app the transactions are working and getting finished. But if I force-quit the app using the the multitasking screen and re-open the app again. the downloading process is not getting finished although as I understood from the docs, it should, here what the docs state: If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of