nsurlsession

Download several files in background (iOS 7 only)

橙三吉。 提交于 2019-12-05 06:16:37
问题 I'm currently developing a podcast application which will run only on iOS 7, and it has a feature that allows to synchronize and download recent episodes in background mode. So it's clear with Synchronization, I implemented the application:performFetchWithCompletionHandler method and call the sync method in it, and when the sync is done I call completionHandler with UIBackgroundFetchResultNewData , or if it fails I call UIBackgroundFetchResultFailed . But when I run the download manager to

NSURLSessionConfiguration HTTPAdditionalHeaders not set

拜拜、爱过 提交于 2019-12-05 06:04:43
Authorization header is set in NSURLSessionConfiguration , however it is not attached to NSURLSessionDataTask . Is this a bug in Foundation framework ? NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPAdditionalHeaders:@{@"Authorization":@"123"}]; // Initialize session with NSURLSessionConfiguration NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest

Upload large video via NSURLSession causes memory pressure crash

扶醉桌前 提交于 2019-12-05 05:31:22
I use the following codes to upload video to server, which requires me to convert the video from video format to NSData . However, when the video is large (e.g. 10 minute video), the App crashes due to memory pressure. How can I resolve this? - (void)uploadVideo { NSDictionary *params = nil; NSString *NSURLSessionIdentifier = [NSString stringWithFormat:@"%@%@",@"my.bundle.identifier.",[self getTimeString]]; NSURLSessionConfiguration *sessionConfig; // SessionConfiguration With iOS Version if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { sessionConfig =

Pause,Resume,Cancel Upload Task Using NSURLSession UploadTask

情到浓时终转凉″ 提交于 2019-12-05 04:06:59
I am developing an app to upload multiple files using NSURLSession, right now my files are successfully uploaded. But now what i want to achieve is to pause,resume and cancel the uploads just like we do in download tasks. Is it possible.? Any help would be appreciated. Thnx I have studied alot but could find nothing .After i tried this on my code assuming this as a download task ,I came to know that we can "pause , resume" upload tasks as well using NSURLSession just we do in downloading tasks. To pause a task simply call [yourUploadTask suspend]; to resume [yourUploadTask resume]; To cancel

NSURLSession delegation: How to implement my custom SessionDelegate class accordingly?

有些话、适合烂在心里 提交于 2019-12-05 03:27:30
问题 Got a singleton class, so called RequestManager, which shall handle requests made by different modules and background tasks of my application. @interface RequestFactory : NSObject - (void)requestDataWith:(NSString *)token id:(NSString *)id sender:(id<RequestFactoryDelegate>)sender; ... @end Then I got another class, so called SessionDelegate, which shall handle all the callbacks during the request. @interface SessionDelegate : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate,

NSURLSession post : difference between uploadTask and dataTask

谁都会走 提交于 2019-12-05 00:45:21
These are my two examples : let config = NSURLSessionConfiguration.defaultSessionConfiguration() config.HTTPAdditionalHeaders = ["Accept": "application/json", "Content-Type": "application/json", "User-Agent": UIDevice.currentDevice().model] var request = NSMutableURLRequest(URL: NSURL(string: "http://XXX")) request.HTTPMethod = "POST" let valuesToSend = ["key":value, "key2":value] var error: NSError? let data = NSJSONSerialization.dataWithJSONObject(valuesToSend, options:NSJSONWritingOptions.PrettyPrinted, error: &error) request.HTTPBody = data if error == nil { let task = NSURLSession

what is the advantage of using Alamofire over NSURLSession/NSURLConnection for networking?

依然范特西╮ 提交于 2019-12-04 22:33:05
Can anyone help me in understanding these question : What is the advantage of using Alamofire over NSURLSession/ NSURLConnection? What are the differences between NSURLSession and NSURLConnection? NSURLConnection is Apple's old API for doing networking (e.g. making HTTP requests and receiving responces), while NSURLSession is their new one. The latter one is higher level and is generally much easier and involves less boilerplate code to use for most application developers - there's basically no reason to use the former except in legacy code that you don't want to update. A bit of history:

NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance

独自空忆成欢 提交于 2019-12-04 22:11:59
When trying to create my own session object NSURLSession() and request an url I get an unrecognized selector exception but when I use the shared session NSURLSession.sharedSession() everything works fine. How come? var url = NSURL(string: "http:/www.google.com") if url != nil { //throws unrecognized selector when dataTaskWithURL is called let session=NSURLSession() session.dataTaskWithURL(url!) //works let sharedSession=NSURLSession.sharedSession() sharedSession.dataTaskWithURL(url!) } You have to init URLSession with a configuration: URLSession(configuration: .default) or use shared session

How to hook NSURLSession methods with theos?

半腔热情 提交于 2019-12-04 20:13:19
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 *)dataTaskWithRequest:(NSURLRequest *)request { NSLog(@"testhook dataTaskWithRequest"); return %orig(request); } %end

NSURLSessionDownloadTask cancelByProducingResumeData return null

让人想犯罪 __ 提交于 2019-12-04 19:34:58
I use NSURLSessionDownloadTask to download a file from server, it is run in a background session. I want to save resume data to resume the download when the app is terminated. However, the call of cancelByProducingResumeData always returns null. I cannot figure out the issue, cause I used to do a sample of resumable download task successful before. Does anybody get the same issue? Do you know if the request satisfies the criteria outlined in the documentation for the cancelByProducingResumeData method? A download can be resumed only if the following conditions are met: The resource has not