nsurlsession

NSURLSession lifecycle and basic authorization

痞子三分冷 提交于 2019-12-09 06:17:51
问题 I can't consistently read response from a server if I use code below. Header: #import <Foundation/Foundation.h> @interface TestHttpClient : NSObject<NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate> -(void)POST:(NSString*) relativePath payLoad:(NSData*)payLoad; @end Implementation: #import "TestHttpClient.h" @implementation TestHttpClient -(void)POST:(NSString*)relativePath payLoad:(NSData*)payLoad { NSURL* url = [NSURL URLWithString:@"http://apps01.ditat.net

Creating a non-tracking in-app web browser

只谈情不闲聊 提交于 2019-12-09 06:00:06
问题 I am trying to create a webview (as an exercise) that does not track or store any browsing history locally. I have made it so that when the webview is closed, it calls the following [[NSURLSession sharedSession]resetWithCompletionHandler:^{}]; but I am finding that things like google search history persists some how between sessions. I have also tried clearing cookies separately through NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie in

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

有些话、适合烂在心里 提交于 2019-12-09 05:27:53
问题 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

AFNetworking Background Session Configuration for iOS 8 Extension

纵然是瞬间 提交于 2019-12-09 05:25:58
问题 I'm currently developing an iOS 8 App Extension, and am having difficulty with this one last piece. In the rest of my app, I use an AFHTTPSessionManager subclass that I instantiate like this: + (MYAPIClient *)sharedClient { static MYAPIClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedClient = [[MYAPIClient alloc] initWithBaseURL:[NSURL URLWithString:kMYBaseURL]]; _sharedClient.requestSerializer = [[MYAPIRequestSerializer alloc] init];

Missing Data with URLSession and JSONDecode in Swift4

杀马特。学长 韩版系。学妹 提交于 2019-12-09 04:32:29
Using Swift4, iOS11.1, Xcode9.1, The following parseData method almost works. Everything seems to work fine (and a correct JSON-data set is fetched by this URLSession and JSONDecode). However, what is really surprising to me is the fact that a normal Browser shows different JSON-data (i.e. 20x as much is fetched than compared to this iOS-URLSession approach). Why is that ?? In the code below, you can find two print statements. The first showing the actual URLRequest-string (including all query- and type-parameters). The second prints the number of fetched JSON data-sets. If you use a Browser

NSURLSession with invalid resume data

一曲冷凌霜 提交于 2019-12-08 23:35:36
问题 I use [NSURLSessionConfiguration defaultSessionConfiguration] to config my url session. I pause a task by calling cancelByProducingResumeData: to produce a resume data, and save it to the disk. When I want to restart the task, I call downloadTaskWithResumeData: . It works well until I restart the app. I kill the app after I pause a task. Then I start my app again, and call downloadTaskWithResumeData , I found that the resume data was invalid. I parse the resume data into NSDictionary and get

NSURLSessionUploadTask how to read server response

允我心安 提交于 2019-12-08 15:00:32
问题 I am using NSURLSessionUploadTask to upload a file. Here are some parts of my code not complete let session:NSURLSession = NSURLSession(configuration: config, delegate: self, delegateQueue: NSOperationQueue .mainQueue()) let sessionTask:NSURLSessionUploadTask = session.uploadTaskWithStreamedRequest(request But the problem is I am unable to get the JSON response the server sends back. The following delegate also not firing but other delegates are firing func URLSession(session: NSURLSession,

Downloading PDF using NSURLSession (HTTP POST) with parameters

邮差的信 提交于 2019-12-08 13:09:47
问题 I have a problem with downloading PDF file using NSURLSession with POST.My download url is different than any other else because it didn't end with file extension name and it also need parameters to download that file. It's from ASPX base server and return url like that http://example.com/DownloadPDF.aspx?File=ES2Ges%2BUA1CEe1150UF3uUgEDeCEMoIuOrJCbwjzVKCEfA6%2F1zKxycl6MMWcjvtk If I have to access the pdf and download it,I have to provide 2 parameters ConfigKeyID and AccessToken .And one

Encoding UIImage to Base64 string not working when transferred to server

孤者浪人 提交于 2019-12-08 11:08:30
问题 Encoding an UIImage as a Base64 string works on the device, but transferring the string to the server somehow corrupts the string and prevents the server from successfully decoding the image. Any suggestions on the problem? // Define params params["thumbnail_base64"] = imageToBase64(blockSet.thumbnailURL) ... // Convert params -> query string let postString = buildQueryString(params) // Define upload URL let uploadURL = NSURL(string: RootURL + UploadFilePath)! // Hit server let request =

Missing Data with URLSession and JSONDecode in Swift4

风格不统一 提交于 2019-12-08 08:59:42
问题 Using Swift4, iOS11.1, Xcode9.1, The following parseData method almost works. Everything seems to work fine (and a correct JSON-data set is fetched by this URLSession and JSONDecode). However, what is really surprising to me is the fact that a normal Browser shows different JSON-data (i.e. 20x as much is fetched than compared to this iOS-URLSession approach). Why is that ?? In the code below, you can find two print statements. The first showing the actual URLRequest-string (including all