nsurlsession

AFHTTPSessionManager posting video swift

半腔热情 提交于 2019-12-04 19:18:51
I am trying to upload a video in background using AFNetworking > AFHTTPSessionManager Post method. I want it to conitune uploading even if the app is suspended. But I get error while executing this code, it logs no error, and points to nowhere in code. I tried every solution available on other posts regarding my scenario, but couldn't get it working. Plesae check my code below and suggest me solution or link me somewhere to make it work { let urlString = BaseUrl + WebLinks.post let appId = NSBundle.mainBundle().bundleIdentifier let config = NSURLSessionConfiguration

NSURLSession: handleEventsForBackgroundURLSession method doesn't run in Background session

China☆狼群 提交于 2019-12-04 16:58:44
application:handleEventsForBackgroundURLSession:completionHandler: doesn't run when the uploads are finished in the background. When all the upload/download tasks are completed in the background then iOS should wake up the app and call the above method. But it doesn't. I have tested this by terminating the app from 'xcode stop' button and also terminated from an exception. I have followed Background Transfer consideration . I have tested this on Apple developer guide: Background example and it is not working. I have also tested this on AppCoda: Background example and it is not working Both of

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

老子叫甜甜 提交于 2019-12-04 16:41:33
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 = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil

How do you know when the NSURLSession object has been invalidated by iOS?

牧云@^-^@ 提交于 2019-12-04 16:05:09
问题 I am seeing an error in my tests where occasionally I get the following iOS error: A background URLSession with identifier {GUID} already exists! Even though I call invalidateAndCancel on the NSURLSession in the cleanup call after every test. I am looking for a way to wait until I am sure the NSURLSession object has been invalidated, before proceeding to the next test. 回答1: When you create your NSURLSession object use the sessionWithConfiguration:(NSURLSessionConfiguration *)configuration

How To Fetch and Parse JSON Using Swift 2 + XCode 7 + iOS 9 [duplicate]

旧街凉风 提交于 2019-12-04 14:53:52
问题 This question already has answers here : How to parse JSON in Swift using NSURLSession (5 answers) Closed 4 years ago . Was looking for useful tutorials for networking with Swift 2 and iOS 9, but it seems that topic has no content online. I have watched the WWDC session Networking with NSURLSession But I couldn't adapt the new API of iOS9 to have an asynchronous way to fetch and parse JSON data. What I have tried: do { if let url = NSURL(string: "site/api.php?option=fetchOps"), let data =

Upload file with NSURLSessionUploadTask in back ground

旧时模样 提交于 2019-12-04 14:08:03
i am uploading multiple files using NSURLSessionUploadTask. I want to run same process in back ground and it works fine for current file. App is not suspended until current file got uploaded successfully. Now, when second files comes to upload, it not start uploading process until i again launch or app became active. Uploading is not falling in between thats good. Is there any way to start next uploading process when first finishes. Second uploading is start also in back ground but that works upto 3 min from app goes in back ground. Here i shows my code: AppDelegate.h @property (nonatomic,

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

为君一笑 提交于 2019-12-04 09:34:13
I am implementing a custom NSURLProtocol , and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection . I have hit an interesting problem and wonder about the internal implementation of the challenge handler of NSURLSession / NSURLSessionTask . - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler; Here I am basically provided with two

Chaining background NSURLSession uploads

白昼怎懂夜的黑 提交于 2019-12-04 09:12:11
Has anyone been successful in chaining NSURLSession background uploads? I am trying to upload a huge video file in 5 MB parts using background upload of NSURLSession. The uploads has to be in order. The whole thing works fine in foreground. I am using AFNetwoking for this, and its a multi part upload. But when the app is in background, the first item uploads fine and starts the second one in background (in setDidFinishEventsForBackgroundURLSessionBlock of AFURLSessionManager). But it stops abruptly (my best guess is in 30 seconds, as an app woken up in background has a max lifetime of 30 sec)

ambiguous use of selector dataTask(with: completionHandler:)

删除回忆录丶 提交于 2019-12-04 09:03:29
I'm trying to get a selector of the dataTask(with:completionHandler:) method defined in URLSession which uses URLRequest object like below, but getting error as there are two methods with slightly two different params names (overloaded methods - 1. one uses URLRequest object as param and another uses URL) : let dataTaskSelector = #selector(URLSession.dataTask(with: completionHandler:)) I have tried a different approach like below (mentioned in https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md ) but it's also giving same error : let mySelector = #selector(

Unit tests with NSURLSession

。_饼干妹妹 提交于 2019-12-04 09:02:39
I'd like to write unit tests for methods that use the shared NSURLSession , and in particular, NSURLSessionDataTask to download data. Basically, I would like the target methods to receive mock responses/data without requiring an internet connection. What is the less unobtrusive way of mocking these components? I was thinking of populating NSURLCache with mock responses and data but I feel this assumes too much of how NSURLSession and NSURLSessionDataTask work. Any other suggestions? I've used OHHTTPStubs to mock responses lately. You just register the stub before you test (example from the