nsurlrequest

How return data from an HTTP request in Swift/Objective C

我们两清 提交于 2019-12-01 11:38:19
I'm trying to use Coinbase's API to get information about my online bitcoin wallet, and I'm trying to use Swift's NSURLSession object to do so. Perhaps I'm missing something obvious in the Apple docs, but after reading through the information about NSURLSession and NSURLSessionTask I still do not understand how to make an HTTP request and then return the body of the response so that the body can persist throughout the life of my app. As of now I only see the ability to use completion blocks which return void, or delegates which either return void themselves or use completion blocks which also

Mutable NSHTTPURLResponse or NSURLResponse

99封情书 提交于 2019-12-01 09:17:19
I need to modify response headers in an NSURLResponse. Is this possible? Colin Barrett I was just talking about this with a friend. My suggestion would be to write a subclass of NSURLResponse. Something along these lines: @interface MyHTTPURLResponse : NSURLResponse { NSDictionary *myDict; } - (void)setAllHeaderFields:(NSDictionary *)dictionary; @end @implementation MyHTTPURLResponse - (NSDictionary *)allHeaderFields { return myDict ?: [super allHeaderFields]; } - (void)setAllHeaderFields:(NSDictionary *)dict { if (myDict != dict) { [myDict release]; myDict = [dict retain]; } } @end If you're

Monotouch + UIWebView = Random Crashes

最后都变了- 提交于 2019-11-30 22:21:10
I'm using the latest stable releases of Mono/Monotouch/MonoDevelop on a iOS 5.0 iPhone and iPad. I have a UIWebView that in the emulator never crashes however randomly on the actual devices it crashes on EXC_BAD_ACCESS. Based on everything I've read with UIWebViews that most likely occurs when the UIWebView gets disposed before it finishes loading. Here is the code I am using in my ViewDidLoad(): var urlAddress = BASE_URL + _page; var nsURL = new NSUrl(urlAddress); var nsURLRequest = new NSUrlRequest(nsURL); _webView.Tag = 10; _webView.ScalesPageToFit = true; _webView.AutosizesSubviews = true;

Detect if PNG file is corrupted in Objective C

一笑奈何 提交于 2019-11-30 15:59:17
问题 I'm downloading jpgs and pngs using NSURLRequest. This works ok but sometimes the files are corrupted. I have seen Catching error: Corrupt JPEG data: premature end of data segment and have this working for jpgs. Does anyone know of a way to do the same for pngs? ie Programatically check if the png data is valid... 回答1: The PNG format has several built in checks. Each "chunk" has a CRC32 check, but to check that you'd need to read the full file. A more basic check (not foolproof, of course)

Detect if PNG file is corrupted in Objective C

╄→尐↘猪︶ㄣ 提交于 2019-11-30 15:41:34
I'm downloading jpgs and pngs using NSURLRequest. This works ok but sometimes the files are corrupted. I have seen Catching error: Corrupt JPEG data: premature end of data segment and have this working for jpgs. Does anyone know of a way to do the same for pngs? ie Programatically check if the png data is valid... The PNG format has several built in checks. Each "chunk" has a CRC32 check, but to check that you'd need to read the full file. A more basic check (not foolproof, of course) would be to read the start and ending of the file. The first 8 bytes should always be the following (decimal)

NSURLRequest won't fire while UIScrollView is scrolling

混江龙づ霸主 提交于 2019-11-30 12:09:24
问题 I have a problem in that I am trying to background load a sound file while the user moves around a UIScrollView... The problem is that I am using NSURLRequest so I can load in the background, but even then it refuses to actually load until the UIScrollView has stopped scrolling. :( Is there anything I can do about this? Thanks! 回答1: The NSURLRequest only manages the request, not the actual connection. Touch events such as scrolling will place the run loop into NSEventTrackingRunLoopMode . By

NSURLRequest: How to handle a redirected post?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 09:03:41
I have a tried and tested use of NSURLRequest (and accompaniments) implementation, that works great for GETs, and POSTs for a given URL. However, I want to now move the target of the URL without changing the URL used by the app, so I'm intending to use a webhop redirect via my DNS provider. This works fine for the GET requests, but the POSTs just hang... no connection response is received. The relevant iOS method for handling a redirect is, -(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse

Request with NSURLRequest

倾然丶 夕夏残阳落幕 提交于 2019-11-30 07:06:14
I'm trying do to an app which uses a database (actually in my localhost), I tried with ASIHTTPRequest but having so much troubles with iOS 5 (I learnt how to use ASIHTTPRequest form there : http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service Now i'm trying with the API provided by Apple : NSURLRequest / NSURLConnection etc,... I read the Apple online guide and make this first code : - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL

Alternative method for NSURLRequest's private “setAllowsAnyHTTPSCertificate:forHost:”?

大城市里の小女人 提交于 2019-11-30 06:42:47
My iPhone application was rejected solely for using the (very safe, it seems) private method +setAllowsAnyHTTPSCertificate:forHost: for NSURLRequest . Is there a non-private API to emulate this functionality? yonel There seems to be a public API for that ;) How to use NSURLConnection to connect with SSL for an untrusted cert? Actually, I'm testing with 10.6.8 and this code still works -- it's using the private API but checking that the selector exists (myurl is the NSURL I'm trying to load into a WebView or an NSURLConnection): SEL selx = NSSelectorFromString(@"setAllowsAnyHTTPSCertificate

UIWebView won't load links with certificate (https:// prefix)

倖福魔咒の 提交于 2019-11-30 04:06:08
I know this has been asked before but I have looked at every answer (there aren't many) and none help me. The issue I am running into is dealing with certificates with my schools e-mail service. The links for the two e-mail services are here: Main school e-mail: https://marauder.millersville.edu/mail/index.pl Computer Science e-mail: https://cs.millersville.edu/cswebmail University student portal (Marauder Mail button on the right doesn't open when clicked in my UIWebView) http://myville.millersville.edu/ At first neither of the websites would load in my UIWebView using a standard NSURL and