UIApplication sharedapplication openURL not working

AndrewSB picture AndrewSB · Apr 14, 2014 · Viewed 18.1k times · Source

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?

Answer

Khawar Ali picture Khawar Ali · Apr 14, 2014

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