12

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?

AndrewSB
  • 951
  • 3
  • 11
  • 25

3 Answers3

8

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

neowinston
  • 7,584
  • 10
  • 52
  • 83
Khawar Ali
  • 3,462
  • 4
  • 27
  • 55
7

Try this:

- (IBAction)facebookButtonPress:(id)sender {
NSLog(@"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/asbreckenridge"]];
}
Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
1

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"

pkamb
  • 33,281
  • 23
  • 160
  • 191
Igor
  • 12,165
  • 4
  • 57
  • 73