nsurlsession

Using NSURLSession inside NSURLProtocol

元气小坏坏 提交于 2019-12-10 12:23:23
问题 I'm trying to create a transparent NSURLProtocol for http:// and https:// connections using NSURLSession. However at the moment, even though the completion handler is being run, URL requests with the app (UIWebView) are coming back blank. Does anybody have any ideas? Code is below: #import "MyURLProtocol.h" // AppDelegate #import "AppDelegate.h" static NSString * const MyURLProtocolHandledKey = @"MyURLProtocolHandledKey"; @interface MyURLProtocol () <NSURLConnectionDelegate

Background fetch and background transfers in iOS to download data (JSON) on bakcground

笑着哭i 提交于 2019-12-10 12:05:33
问题 I am in the process of upgrading one of my apps to iOS 7 and thought of trying out the new multitasking apis. I am planning to use Background Fetching or Silent push notifications to keep my content uptodate. Basically set of JSON values. Most of the documentation/code I looked through download videos or images and I have following questions... If we use Background Fetching or Silent push notifications, do we need to download data using a separate backgroundSessionConfiguration ? Or can we do

Saving URL data to a variable

江枫思渺然 提交于 2019-12-10 11:55:26
问题 So I am trying to get a simple string of data back from a RESTful API. Here is what a response looks like: Hello It is not formatted in XML or JSON or anything just a simple string because only one word is being passed back at a time. So here is what my swift looks like: let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in if error != nil { println("error: \(error.localizedDescription): \(error.userInfo)") } var withNewLine:NSString = NSString(data:

Trouble with NSURLSession multipart/form-data post request

廉价感情. 提交于 2019-12-10 11:36:47
问题 Im having some trouble with sending text and images in the same post request to my server. I think the problem has to do with the way i set my boundary. Im using swift with ios9. I followed instructions here ios Upload Image and Text using HTTP POST doing my best to convert the obj-c into swift however when i post a request to my server, whenever i try to access the post data such as $_POST["key"] i get an undefined index error. Here is the code i use to setup the http request, can anyone

NSURLSessionDownloadTask resumes automatically all task while in background

吃可爱长大的小学妹 提交于 2019-12-10 10:55:01
问题 I have requirement to download files in serial order. Currently I am able to do that while app is in foreground. Following is the logic I have used. Create all tasks for downloading. Resume one at a time and as the current finishes resume the next one from URLSession:task:didCompleteWithError: . This logic is working while app is in foreground but once app started to run in background(By crashing) and we again run the app before download finishes all the tasks state has been changed to resume

NSURLSession delegate methods not called

不问归期 提交于 2019-12-10 09:28:18
问题 I have created a very simple app to download a text file from my web server. I have this working perfectly with NSURLConnection, but am trying to migrate over to NSURLSession instead. The issue I am having is that none of the delegate methods are being called. My server is password protected so I need to use the basic http authentication to access the file, but when the didReceiveChallenge method is never called. The line of code [getFileTask resume] seems to have no effect on anything. My

How to hook NSURLSession methods with theos?

左心房为你撑大大i 提交于 2019-12-09 23:49:42
问题 I created a tweak project using rpetrich's theos and wanted to hook NSURLSession methods but the hooks don't seem to get invoked? Why? This is my Tweak.xm code: %hook NSURLSession - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler { NSLog(@"testhook dataTaskWithRequest:completionHandler:"); return %orig(request, completionHandler); } - (NSURLSessionDataTask *

Domain=NSURLErrorDomain Code=-1001 “The operation couldn’t be completed. (NSURLErrorDomain error -1001.)”

妖精的绣舞 提交于 2019-12-09 20:11:20
问题 my program is write for upload the picture from the cam,sample code below: #define WEBSERVICE_URL @"http://192.168.0.104/upload.php" - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{ UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData *imageData = UIImagePNGRepresentation(selectedImage); NSMutableURLRequest *request = [

unable to upload file using NSURLSession multi-part form data in iOS

走远了吗. 提交于 2019-12-09 14:27:37
问题 I am trying to upload a video / image file using - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL; method using multi-part form data. But somehow i am not able to upload the file and i am getting " stream ended unexpectedly " error. Requirements Upload a video / image file to server App should support background uploads (Continue the upload process even after app goes into background) Server expects the data to be sent using multi-part form

Networking pattern based on NSURLSession

喜欢而已 提交于 2019-12-09 12:42:41
问题 I've been traditionally using a pattern where NSOperation subclasses create and manage their own NSURLConnection. The NSOperation subclass is instantiated by the view controller and will do its work without bothering the controller until it has finished. When it finishes retrieving data, it executes the completion block supplied by the view controller. ViewController instantiates NSOperation subclass (which encapsulates URL, parameters etc) NSOperation subclass instanciates NSURLConnection