nsurlconnection

NSURLConnection returning error instead of response for 401

╄→гoц情女王★ 提交于 2021-02-07 03:40:13
问题 I have a web API that, for a specific request returns status code 200 if everything went ok, and 401 if the user is not logged in based on an Authorization token. Everything works fine if the response status is 200, but doesn't seem to work properly if the response status is 401, returning a connection error with code -1012, while the response is nil. So, the following code: [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data,

NSURLConnection returning error instead of response for 401

你说的曾经没有我的故事 提交于 2021-02-07 03:39:09
问题 I have a web API that, for a specific request returns status code 200 if everything went ok, and 401 if the user is not logged in based on an Authorization token. Everything works fine if the response status is 200, but doesn't seem to work properly if the response status is 401, returning a connection error with code -1012, while the response is nil. So, the following code: [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data,

How do I remove/decode URL percent encoding?

不问归期 提交于 2021-02-04 14:28:06
问题 I want to take a url and convert it to a more readable format. For example I have the following link: http://en.wikipedia.org/wiki/S%C3%A1ndor_Font I take away the unnecessary parts and am left with "S%C3%A1ndor_Font" as a NSString . Is there any sort of way to convert this into "Sándor Font" (what it actually should be), without having to type out every single combination of special characters and replacing each part of the string? To demonstrate how I want to use this, I wrote the following

iOS网络编程之三——NSURLConnection的简单使用

╄→гoц情女王★ 提交于 2021-02-03 07:05:49
iOS网络编程之三——NSURLConnection的简单使用 一、引言 在iOS7后,NSURLSession基本代替了NSURLConnection进行网络开发,在iOS9后,NSURLConnection相关方法被完全的弃用,iOS系统有向下兼容的特性,尽管NSURLConnection已经被弃用,但在开发中,其方法依然可以被使用,并且如果需要兼容到很低版本的iOS系统,有时就必须使用NSURLConnection类了。 二、使用NSURLConnection进行同步请求 对于网络请求分为同步和异步两种,同步是指在请求结果返回之前,程序代码会卡在请求处,之后的代码不会被执行,异步是指在发送请求之后,一边在子线程中接收返回数据,一边执行之后的代码,当返回数据接收完毕后,采用回调的方式通知主线程做处理。 使用如下方法进行NSURLConnection的同步请求: NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"]; NSURLRequest * request = [NSURLRequest requestWithURL:url]; NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error

Best practice to replace a synchronous NSURLConnection with NSURLSession

我是研究僧i 提交于 2020-04-30 07:38:05
问题 As NSURLConnection sendSynchronousRequest:returningResponse:error:&connectionError is set deprecated I will have to replace an Importer I wrote a long time ago. The Importer does the following: It fetches data from API-A. The data there can be on multiple pages. It uses the data from the first fetch (also multipage) to query data from API-B and merges Results from the API-B query will be merged with data from API-A I implemented this with a background-operation where I use methods for each

UITableView refresh problems with an NSURLConnection-asynchronously laden NSMutableArray

房东的猫 提交于 2020-03-05 21:40:05
问题 I am currently approaching Swift (I have been coding in Objective-C for some years) and I am trying to develop a companion app to my video-surveillance system. What my app do is: Connect to a password-protected web site and obtain a list of the last snapshots uploaded by either one of the three existing ip-cameras. For each of these shots, I create a PicInfo object with a temporary pic. I then attempt to asynchronously download the pics and store them in an UIImage property. From there, I

NSURLCache doesn't cache

流过昼夜 提交于 2020-03-03 04:39:14
问题 I'm using Xcode 6.1 (6A1030), both iOS7 & iOS8 Simulators. NSURLCache does not seem to cache anything. I use the "Cache-Control" header. My server returns the Cache-Control header with 'max-age=6000'. In this example, I tamper a request from Google, which is also not cached: AppDelegate: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { var URLCache = NSURLCache(memoryCapacity: 500 * 1024 * 1024, diskCapacity: 500 *

NSURLCache doesn't cache

喜夏-厌秋 提交于 2020-03-03 04:38:25
问题 I'm using Xcode 6.1 (6A1030), both iOS7 & iOS8 Simulators. NSURLCache does not seem to cache anything. I use the "Cache-Control" header. My server returns the Cache-Control header with 'max-age=6000'. In this example, I tamper a request from Google, which is also not cached: AppDelegate: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { var URLCache = NSURLCache(memoryCapacity: 500 * 1024 * 1024, diskCapacity: 500 *

How do I prevent cellForItemAtIndexPath from executing before I have my data ready?

核能气质少年 提交于 2020-02-08 06:57:38
问题 I'm returning images as Base64 data from my server to my application but I'm not going to ask my server for the images until I have the users' location, which I'm only going to have after the user logs in to the application (which displays the UICollectionView). My problem is that collectionView:cellForItemAtIndexPath: is being called before I have the data ready for the cells. Which ways could I prevent this method from being called until my NSURLConnection has received a full response from

MonoTouch: How to download pdf incrementally as indicated in the Apple slides “Building Newsstand Apps”, Session 504?

自作多情 提交于 2020-02-04 07:20:13
问题 This is a followup to : MonoTouch: How to save a huge PDF downloaded from an URL incrementally? I'm trying to follow the guidelines indicated by the Apple slides of the Newsstand presentation ("Building Newsstand Apps", Session 504): http://adcdownload.apple.com//wwdc_2011/adc_on_itunes__wwdc11_sessions__pdf/504_building_newsstand_apps.pdf Apple recommends the use of the NSURLConnection Delegate and NKAssetDownload for downloading and resuming the newsstand content, but I don't understand