Open url from PHP link iphone
Hey all, I have a phpmyadmin site, that I use for my databasing/updating my iphone app
I am looking to do the following:
- when a user clicks a UIButton
- this button will grab a url from a php file (on my server) and inside that php file it will grab a URL from one of my tables, and continue to open safari to that URL
I have been trying to do this for hours, but with little experience with the iOS dev kit, I am still learning :-)
converting the text in my php file from text to open a URL in the iOS safari with that url posted inside my php file....
here is what I have done
- my h file is setup with the -(IBAction)linkbutton;
my .m file has.....
-(IBAction)LinkButton{
NSURL *linkurl = [NSURL URLWithString:@"http://mydomain.com/link.php"];
NSString *linkresponse = [[NSString alloc] initWithContentsOfURL:linkurl];
[[UIApplication sharedApplication] openURL:linkurl];
however, i know I have to use linkres开发者_JS百科ponse
rather then linkurl
, since it is converted that php file which is another URL (ie, youtube video or other link), however with linkresponse
it does CRASH, and with linkurl
it opens my PHP file in safari, with the appropriate link displaying on the page, as my PHP file is setup correctly....
any help would be great
If you want to get the contents of a URL, you should read Apple's URL Loading System Programming Guide. -[NSString initWithContentsOfURL:]
does do what its name implies: it initializes with the contents of a URL. However, that method is mainly (supposed to be) used to load the contents of local files with URLs like http://localhost/...
. For this, you should use URL fetching instead.
Does that make sense?
精彩评论