isn't launching my URL?
I've got a question regarding sharedApplication.
I'm reading a particular link from my XML file onto the app itself, and had it stored inside a NSString. I tried to convert the NSString to NSURL for sharedApplication to open it, but it doesn't seems to work. The only way for me to get it to work is to define the string myself without passing in any information from the XML.
Currently, my code stands like this:
NSString *URLstring = [item objectForKey@"officialweb"]; // Reading from XML
NSURL *url = [NSURL URLWithString:URLstring];
NSLog(@"url: %@", url); // Displays (null)
printf("url: %s, \n", [URLstring UTF8String]); // Displays proper URL
[UIApplication sharedApplication] openURL:url];
If I use the codes above, Safari will not launch and the NSURL only returns a (null) as results.
I've searched the site and googled for solutions, but the best I saw was to include:
URLstring = [URLsting stringByAddingPercentEscapeUsingEncoding: NSUTF8StringEncoding]];
into the code. The app finally launches Safari after adding开发者_如何学Go that, but my URL turns out in an extremely weird manner. Something like "http://url.com/%0%0%A" or whatnot instead of the "http://url.com" as stated in my XML file.
I would really appreciate it if anyone could point me in the proper direction regarding this.
What happens if you say NSURL *url = [NSURL URLWithString:[URLstring UTF8String]]; ?
精彩评论