nsurlsession

Right Way for changing timeoutIntervalForRequest in Alamofire

江枫思渺然 提交于 2019-12-01 21:54:15
I changed timeoutIntervalForRequest with let manager = Alamofire.SessionManager.default manager.session.configuration.timeoutIntervalForRequest = 3 manager.request(url).response {} but seems not worked, Any suggestion? This worked for me :) let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = TimeInterval(7) configuration.timeoutIntervalForResource = TimeInterval(7) let session = URLSession(configuration: configuration) let task = session.dataTask(with: url) {} Changes to the configuration of an already initialized URLSession have no effect, per Apple's

UI get blocked when using NSURLSession

时光总嘲笑我的痴心妄想 提交于 2019-12-01 20:08:11
I'm working on a project which requires a login form, using a webservice for authentication. I have no issue connecting to the server but it seems that NSURLSession blocks my user interface and I really dont know why after a lot of debugging. For simplicity, here's my code in short: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"example.com/service"]]; //1 //_sessionLogin = [NSURLSession sessionWithConfiguration:sessionConfigurationLogin delegate:self delegateQueue:nil]; //2 //Whether I use 1 or 2, it acts the same way _sessionLogin =

NSURLErrorDomain Code=-1001 error when a http post request is sent

随声附和 提交于 2019-12-01 16:09:51
I am using the following code to post an image to my server. @IBAction func postButtonPressed(sender: UIButton) { let task = NSURLSession.sharedSession().dataTaskWithRequest(createRequest("http://xx.xx.xxx.xxx/xxxx/"), completionHandler: { data, response, error in println(NSString(data: data, encoding: NSUTF8StringEncoding)) }) task.resume() } where createRequest() creates the required NSURLRequest object. This works fine when I use a simulator . The problem is that I am getting the following error when I run my app on an iPhone. Error Domain=NSURLErrorDomain Code=-1001 "The operation couldn’t

Swift 3: URLSession / URLRequest Not Working

雨燕双飞 提交于 2019-12-01 16:07:47
I am still trying to convert our application from Swift 2 over to Swift 3 because I am being forced to since all of our Apple devices are now running iOS 10. I have gone through the code conversion and thought I was doing well however, while attempting to debug my JSON issues (posted in another question), I am now dealing with requests not even being sent. let params: [String:AnyObject] = [ "email":"\(self.preferences.string(forKey: "preference_email")!)" as AnyObject ] let requestParams: [String:AnyObject] = [ "action":"601" as AnyObject, "params":params as AnyObject ] do { let requestObject

Inside dataTaskWithRequest is not Executing. In Swift While Hitting the API

时光怂恿深爱的人放手 提交于 2019-12-01 14:53:38
Same Data when I am hitting with POSTMAN I m getting the desired response. But in my Function inside dataTaskWithRequest I am Not Getting Any Response. func sendData (){ let url = NSURL(string: "http://www.example.com/quiz-school/mobileData/request.php?request=QuizTotal&module=PQ")! let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions()) request.setValue("application/json", forHTTPHeaderField: "Content-Type") let task = NSURLSession.sharedSession().dataTaskWithRequest(request){

Background Upload With Stream Request Using NSUrlSession in iOS8

让人想犯罪 __ 提交于 2019-12-01 13:42:05
Previously in iOS7 when we try to upload with stream request in background we get following exception Terminating app due to uncaught exception 'NSGenericException', reason: 'Upload tasks in background sessions must be from a file' But in iOS8 there is no exception when we try to upload with stream in background. Now my question is 1) Is backgourd upload with uploadTaskWithStreamedRequest: allowed in iOS8? 2) In iOS8 i am using background NSURLConfiguration with uploadTaskWithStreamedRequest . I am using -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task needNewBodyStream:

Inside dataTaskWithRequest is not Executing. In Swift While Hitting the API

吃可爱长大的小学妹 提交于 2019-12-01 13:36:31
问题 Same Data when I am hitting with POSTMAN I m getting the desired response. But in my Function inside dataTaskWithRequest I am Not Getting Any Response. func sendData (){ let url = NSURL(string: "http://www.example.com/quiz-school/mobileData/request.php?request=QuizTotal&module=PQ")! let request = NSMutableURLRequest(URL: url) request.HTTPMethod = "POST" request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions()) request.setValue("application/json",

Uploading file using NSURLSessionUploadTask to PHP server

大憨熊 提交于 2019-12-01 13:17:17
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 } }]; // Run the task [task resume]; I have a PHP server (using Laravel) running under nginx to handle

WebService API Method in Swift 3 and Swift 4?

非 Y 不嫁゛ 提交于 2019-12-01 12:37:33
I am new to Swift iOS and i want to create a separate method in separate class(like NSObject ) of web services so that i can use it in any ViewController and parse any type of JSON response using NSURLSession and Alamofire . Could someone help me. class WebRequester: NSObject { static let shared = WebRequester() let session = URLSession.shared func request(urlStr:String, parameter:String, token:String? = nil, callback:@escaping (_ result:NSDictionary?, error:Error?) -> Void) { let url = URL(string: BaseURL + urlStr) debugPrint("=====================") debugPrint(url ?? "") debugPrint(parameter

Simple example of NSURLSession with authentication

偶尔善良 提交于 2019-12-01 12:16:15
I have written a REST service that serves up some data. It is passcode protected. I am trying to write a background process that will grab the data and stuff it into a sqlLite db I have in the app. I did this initially without authentication using : - (void) callWebService { dispatch_sync(kBgQueue, ^{ NSData* data = [NSData dataWithContentsOfURL: scoularDirectoryURL]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES]; }); } This worked fine but I don't think I can add authentication to that. If I can I would just use that. What I am looking for is a