nsurlsession

Transition from RestKit to pure AFNetworking 2.0

爱⌒轻易说出口 提交于 2019-12-03 06:47:50
问题 I'd been using RestKit for the last two years, but recently I've started thinking about transition from these monolith framework as it seems to be really overkill. Here's my pros for moving forward: There is big need in using NSURLSession for background fetches and RestKit has only experimental branch for transition to AFNetworking 2.0. No actual dates when transition will be finished. (Main Reason) No need for CoreData support in network library as no need for fully functional offline data

Uploading Image NSData via POST and NSURLSession

亡梦爱人 提交于 2019-12-03 06:34:45
I'm trying to upload a single UIImage to a server, and everything seems to be okay except that the image is never uploaded. This is the code I'm using to upload the image in iOS: const NSString *boundaryConstant = @"----------V2ymHFg03ehbqgZCaKO6jy"; const NSString *fileParamConstant = @"photo"; NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:nil]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *contentType = [NSString

How to get backgroundSession NSURLSessionUploadTask response

[亡魂溺海] 提交于 2019-12-03 06:17:28
问题 I have implemented a NSURLSession that runs in the background (so it can continue the task using the system deamon even when the app is suspended). The issue is that -(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler is never called. I need to know the response status so I can handle properly the upload failure. According to another post,

NSURLSessionTask never calls back after timeout when using background configuration

耗尽温柔 提交于 2019-12-03 05:47:17
问题 I am using NSURLSessionDownloadTask with background sessions to achieve all my REST requests. This way I can use the same code without have to think about my application being in background or in foreground. My back-end has been dead for a while, and I have taken that opportunity to test how does NSURLSession behave with timeouts. To my utter surprise, none of my NSURLSessionTaskDelegate callbacks ever gets called. Whatever timeout I set on the NSURLRequest or on the NSURLSessionConfiguration

Upload NSURLSesssion becomes invalidated in sharing extension in ios8 with error NSURLErrorDomain Code=-995

安稳与你 提交于 2019-12-03 05:47:05
I try to upload an image using NSURLSession in shared extension in iOS 8 but have this error instantly after calling [task resume] Error Domain=NSURLErrorDomain Code=-995 "The operation couldn’t be completed. (NSURLErrorDomain error -995.)" here is my code: NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:DEFAULT_SHARE_SESSION_ID]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:self.queue]; NSURLRequest *request = [self getMultipartUploadRequest:data url:url albumId

Set number of concurrent downloads with NSURLSessionDownloadTask

ε祈祈猫儿з 提交于 2019-12-03 04:52:23
问题 I'm using the new NSURLSession API and allowing the user to download files. I'd like to try and tell my NSURLSession how many simultaneous downloads to run, but I don't see a way to do it. I'd like to try to avoid managing the download tasks myself, would be much better if I could tell the system how many to allow instead - that would be better for queuing background downloads as well when my app isn't running. Is there a way to do this? 回答1: You can set it in the NSURLSessionConfiguration

Maintain Session information by handling cookies in iOS

拥有回忆 提交于 2019-12-03 03:23:28
I am new in iOS development. I am using NSURLSession to manage session information. below is the sample code I use to call any server API, NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { }]; My flow of application is, If not logged in -> Login (call login api) Else Go to home screen and call other APIs. My problem here is, once the application is removed from memory, the session information is not maintained and I have to call Login again. My requirement is something like

How To Download Multiple Files Sequentially using NSURLSession downloadTask in Swift

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an app that has to download multiple large files. I want it to download each file one by one sequentially instead of concurrently. When it runs concurrently the app gets overloaded and crashes. So. Im trying to wrap a downloadTaskWithURL inside a NSBlockOperation and then setting the maxConcurrentOperationCount = 1 on the queue. I wrote this code below but it didnt work since both files get downloaded concurrently. import UIKit class ViewController : UIViewController , NSURLSessionDelegate , NSURLSessionDownloadDelegate {

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

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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, NSURLSessionDataDelegate> @property (weak, nonatomic) id

Swift 3 NSURLSession/NSURLConnection HTTP load failed when connecting to a site with authentication

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I've seen this error around before and it seems the remedy is to add info to the .plist file. I've tried each of the ones I've seen: How do I load an HTTP URL with App Transport Security enabled in iOS 9? NSURLSession/NSURLConnection HTTP load failed on iOS 9 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) on a subdomain? Still my program results in the same error thrown: 2017-05-08 08:29:37.781075-0400 xxxx[3256:408961] [] nw_coretls_callback_handshake_message_block_invoke_3 tls_handshake_continue: [