UIApplication sharedapplication openURL not working
Asked Answered
S

3

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?

Sprouse answered 14/4, 2014 at 19:35 Comment(0)
B
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

Boscage answered 14/4, 2014 at 19:37 Comment(3)
It is kind of strange, their seems to be no problem with the codeBoscage
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.facebook.com/asbreckenridge" ]]; Not workingGrainger
Have you found any solution for opening www.facebook.comTailpipe
L
7

Try this:

- (IBAction)facebookButtonPress:(id)sender {
NSLog(@"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/asbreckenridge"]];
}
Lloyd answered 14/4, 2014 at 19:42 Comment(2)
Awesome, I dont know what was wrong but it's working nowSprouse
The http:// was missing. In general the additional brackets with the encoding is not a bad thing to do. But in case of this constant URL it does not have any effect.Lloyd
U
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"

Underproof answered 27/10, 2016 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.