nsurlsession

Get the data from NSURLSession DownloadTaskWithRequest from completion handler

旧时模样 提交于 2019-12-18 15:48:25
问题 So I'm having hard time understanding something. This are the things I understand about NSURSession : Generally , I have 2 options for (as far as I know) DataTask(e.x dataTaskWithRequest) And DownloadTask(e.x DownloadTaskWithRequest ) - Using their delegate method , or use the completion handler , Can't do both. I have managed to receive DATA using dataTaskWithRequest like this : let request = NSMutableURLRequest(URL: dataSourceURL!) request.HTTPMethod = "POST" let postString = "lastid=\(id)"

NSURLSession with Token Authentication

℡╲_俬逩灬. 提交于 2019-12-18 10:56:11
问题 I have the following code in my iOS project and I want to convert to use NSURLSession instead of NSURLConnection . I am querying a REST API which uses a token-based HTTP Authentication scheme but I cannot find an example of how to do it. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; NSString *username = [[NSUserDefaults standardUserDefaults] stringForKey:@"Username"]; NSString *token = //GET THE TOKEN FROM THE KEYCHAIN NSString *authValue =

Swift 4 - Get an Upload Image Progress using URLSession

我与影子孤独终老i 提交于 2019-12-18 09:54:25
问题 I have this kind of code below func upload(){ let img = UIImage(named: "1") let imgData = UIImageJPEGRepresentation(img!, 1) let data = imgData?.base64EncodedString() var request = URLRequest(url: URL(string: url)!) request.httpMethod = "POST" request.setValue("\(auth)", forHTTPHeaderField: "Authorization") request.setValue("application/xml", forHTTPHeaderField: "Content-Type") var postString = "<uploadrequest>" postString += "<folderid>123</folderid>" postString += "<folder_name>images<

iOS: NSURLSession category methods not being found at runtime

感情迁移 提交于 2019-12-18 04:36:24
问题 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 <unknown>: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

How to get data from blocks using NSURLSession?

邮差的信 提交于 2019-12-18 01:03:38
问题 I have problem with this block. I trying to get the data inside the block of NSURLSession . here's my code -(NSDictionary *) RetrieveData{ NSURLSession * session = [NSURLSession sharedSession]; NSURL * url = [NSURL URLWithString: self.getURL]; dataList =[[NSDictionary alloc] init]; NSURLSessionDataTask * dataTask = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { self.json = [NSJSONSerialization JSONObjectWithData:data options:0 error

Domain=NSURLErrorDomain Code 1202

陌路散爱 提交于 2019-12-17 23:38:39
问题 Hi I receive the following error: Error Domain=NSURLErrorDomain Code=-1202 \"The certificate for this server is invalid. You might be connecting to a server that is pretending to be “server-prod.name-cloud.com” which could put your confidential information at risk.\" UserInfo={NSErrorFailingURLStringKey= https://server-prod.name-cloud.com /v3/project/session/926B9E6BE31B/, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3,

NSURLSession and amazon S3 uploads

非 Y 不嫁゛ 提交于 2019-12-17 21:48:20
问题 I have an app which is currently uploading images to amazon S3. I have been trying to switch it from using NSURLConnection to NSURLSession so that the uploads can continue while the app is in the background! I seem to be hitting a bit of an issue. The NSURLRequest is created and passed to the NSURLSession but amazon sends back a 403 - forbidden response, if I pass the same request to a NSURLConnection it uploads the file perfectly. Here is the code that creates the response: NSString

Why is a HTTPS NSURLSession connection only challenged once per domain?

十年热恋 提交于 2019-12-17 19:26:42
问题 When connecting via HTTPS to a server, I implement the NSURLSessionDelegate method URLSession:didReceiveChallenge:completionHandler: to implement some custom functionality. The problem is that this delegate method is only being called the first time a request is made (subsequent requests do not invoke this method). My custom functionality requires the delegate method to be called for every request. Here's an example: - (IBAction)reload:(id)sender { NSURLSession *session = [NSURLSession

iOS: Does force quitting the app disables background upload using NSURLSession?

只谈情不闲聊 提交于 2019-12-17 18:35:19
问题 The question is around NSURLSession and NSURLSessionUploadTask . I'm uploading large files to server and noticed that when I force quit the app the whole background upload just stops. However, when upload starts while app is running through the Xcode/debugger, then my upload completes just fine even when I stop the app running via Xcode 'stop' button. I suspect that force quitting the app using Xcode simulates an iOS system command and not a user action. So my question is whether it's true

Background upload multiple images using single NSURLSession uploadTaskWithRequest

假如想象 提交于 2019-12-17 18:07:45
问题 I want to upload multiple images in background using a single uploadTaskWithRequest method. While trying the following code returns Upload tasks from NSData are not supported in background sessions...please how to achieve this func createRequest (param : NSDictionary ,imagearray :NSMutableArray, strURL : String) -> NSURLRequest { let boundary = generateBoundaryString() let url = NSURL(string: strURL) let request = NSMutableURLRequest(URL: url!) request.setValue("multipart/form-data; boundary=