nsurlsession

How to return NSData from NSURLSessionDataTask completion handler

爱⌒轻易说出口 提交于 2019-11-30 15:11:07
问题 I am trying to make a simple class that I can use to call a post web service. Everything is working perfectly except that I am not able to return the NSData . This is my code: + (NSData *)postCall:(NSDictionary *)parameters fromURL:(NSString *)url{ NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSMutableArray *pairs = [[NSMutableArray alloc]init]; for(NSString

Uploading image to server Detail Explanation for Beginner

我的未来我决定 提交于 2019-11-30 15:07:44
问题 I'm working on uploading an image to a server from last two days as there are tons of questions about uploading an image through AFNetworking and NSURLSession and other methods of uploading all I'm asking is I didn't found a single answer explaining the whole concept about how the things work and what is going on under the hood I searched youtube also all the stuff are available in Swift and trust me no Explanation at all and from my result I found this answer is something that looks familiar

My NSURLSessionDelegate methods are not getting called during a background download

你说的曾经没有我的故事 提交于 2019-11-30 14:01:27
问题 I'm trying to set up a download using NSURLSession that will continue in the background. I have a singleton class called DownloadManager which builds the NSURLSession and starts a download task like this: - (id)init { self = [super init]; if (self) { self.queue = [[NSOperationQueue alloc] init]; self.queue.maxConcurrentOperationCount = 1; // Initialize the background session. self.session = [self backgroundSession]; } return self; } - (NSURLSession *)backgroundSession { static NSURLSession

URLSessionDidFinishEventsForBackgroundURLSession Not Calling- Objective-C

本小妞迷上赌 提交于 2019-11-30 13:41:21
NSURLSession Delegate method URLSessionDidFinishEventsForBackgroundURLSession is not Calling ? I already enabled the Background Modes in project capabilities settings. Here is the code AppDelegate.h Method @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (nonatomic, copy) void(^backgroundTransferCompletionHandler)(); @end AppDelegate.m Method -(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler{ self

NSURLSession and stream upload in background

痞子三分冷 提交于 2019-11-30 13:37:21
I have some problems with using NSURLSession to upload photos from Asset Library to the server. At first NSURLSession doesn't support streaming upload. I got an exception when trying to using that: @property (nonatomic, strong) NSURLSession *uploadSession; ... _uploadSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfiguration:kUploadBackgroundURLSessionIdentifier] delegate:self delegateQueue:nil]; ... NSURLSessionUploadTask *task = [self.uploadSession uploadTaskWithStreamedRequest:URLRequest]; This is an exception: Terminating app due to uncaught

Uploading image to server Detail Explanation for Beginner

做~自己de王妃 提交于 2019-11-30 13:24:43
I'm working on uploading an image to a server from last two days as there are tons of questions about uploading an image through AFNetworking and NSURLSession and other methods of uploading all I'm asking is I didn't found a single answer explaining the whole concept about how the things work and what is going on under the hood I searched youtube also all the stuff are available in Swift and trust me no Explanation at all and from my result I found this answer is something that looks familiar to me //Init the NSURLSession with a configuration NSURLSessionConfiguration *defaultConfigObject =

Get the data from NSURLSession DownloadTaskWithRequest from completion handler

爱⌒轻易说出口 提交于 2019-11-30 13:04:04
So I'm having hard time understanding something. This are the things I understand about NSURSession : Generally , I have 2 options for (as far as I know) DataTask(e.x dataTaskWithRequest) And DownloadTask(e.x DownloadTaskWithRequest ) - Using their delegate method , or use the completion handler , Can't do both. I have managed to receive DATA using dataTaskWithRequest like this : let request = NSMutableURLRequest(URL: dataSourceURL!) request.HTTPMethod = "POST" let postString = "lastid=\(id)" request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) let task = NSURLSession

IOS9 SSL error with NSURLSession

℡╲_俬逩灬. 提交于 2019-11-30 12:59:57
I have developed an IOS App that is communicating with a Server using HTTPs (I'm also the developer of the server, it's embedding a Tomcat server). This App is working without any issues with IOS8 but it's not with IOS9. I get the following error when sending an HTTPs request: Session download has failed : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x7fa9c44b2e40 {NSErrorFailingURLStringKey=https://127.0.0.1:8443/MyServer/MyApp, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?,

NSURLSession的文件下载

主宰稳场 提交于 2019-11-30 10:55:52
小文件的下载,代码示例: //NSURLSession的下载 [[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"http://gss0.baidu.com/-fo3dSag_xI4khGko9WTAnF6hhy/lvpics/w=600/sign=1350023d79899e51788e391472a5d990/b21bb051f819861810d03e4448ed2e738ad4e65f.jpg"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { //回到主线程刷新界面 dispatch_async(dispatch_get_main_queue(), ^{ self.imageView.image = [UIImage imageWithData:data]; }); }] resume] ; 大文件的下载,代码示例: #import "ViewController.h" @interface ViewController ()<NSURLSessionDataDelegate> @property (weak,

NSURLSession + server with self signed cert

谁说我不能喝 提交于 2019-11-30 10:46:42
问题 I have an app that is production along with a development server that has a self signed certificate. I am attempting to test NSURLSession and background downloading but can't seem to get past - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler When I use NSURLConnection I am able to bypass it using: - (BOOL)connection