Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIApplication sharedapplication openURL not working

I have this method

- (IBAction)facebookButtonPress:(id)sender {
    NSLog(@"fb hit");
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"www.facebook.com/asbreckenridge" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}

and I don't understand why safari doesnt open the link. I get the 'fb hit' logged, so the method is being called, but it doesnt open the link in Safari, what am I doing wrong?

like image 720
AndrewSB Avatar asked Apr 14 '14 19:04

AndrewSB


3 Answers

Try it without the encoding like this.

- (IBAction)facebookButtonPress:(id)sender {
    NSLog(@"fb hit");
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.facebook.com/asbreckenridge"]];
}

Also try changing the URL to http://www.facebook.com/asbreckenridge

like image 162
Khawar Ali Avatar answered Nov 18 '22 22:11

Khawar Ali


Try this:

- (IBAction)facebookButtonPress:(id)sender {
NSLog(@"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/asbreckenridge"]];
}
like image 7
Hermann Klecker Avatar answered Nov 18 '22 21:11

Hermann Klecker


In my case problem was in extra "/" at the end.

doesn't work:
@"http://www.facebook.com/asbreckenridge/"

works fine:
@"http://www.facebook.com/asbreckenridge"

like image 1
Igor Avatar answered Nov 18 '22 22:11

Igor