iphone execute php url
Beginner question - I have a full URL (in an NSString variable "temp") which I want the application to execute in the background once the user finishes a flow in my iPhone app. I'm having a bit of a problem getting anything to work.
Basically I need to (1) execute the php URL and (2) capture the response and display it back to the user.
Any help is greatly apprecia开发者_如何学Goted!
Thanks
This has been discussed before. Here is a good tutorial web requests
In essence, you need NSURLConnection.
This answer hold all the clues :)
Object-c/iOS :How to use ASynchronous to get a data from URL?
In brief, something like the following. The keys being:
- have the url of the content you want
- use dataWithContentsOfURL to get the actual byes
- create a file
save the image bytes
If (![fileManager fileExistsAtPath:[destinationAddress stringByAppendingPathComponent:filename]]) { NSError** error; NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:srcAddress] options:NSDataReadingMapped error:error]; if (imageData != NULL) { BOOL fileCreated = [fileManager createFileAtPath:destinationAddress contents:imageData attributes:nil]; }
}
Also, use NSURLConnection, if you want to download off the main UI thread (good idea)
精彩评论