openURL not opening Safari

Jon Erickson picture Jon Erickson · Sep 8, 2012 · Viewed 9.7k times · Source

I am trying to use an action sheet to open safari with a link. The variable is set correct and displays the link accordingly, but for some reason, Safari won't open and I cannot figure out why...

Here's the code:

-(void)actionSheet {
    sheet = [[UIActionSheet alloc] initWithTitle:@"Options"
                                    delegate:self
                           cancelButtonTitle:@"Cancel"
                      destructiveButtonTitle:nil
                           otherButtonTitles:@"Open in Safari", nil];

    [sheet showInView:[UIApplication sharedApplication].keyWindow];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex != -1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.url]];
    }
}

Answer

Hardik Mamtora picture Hardik Mamtora · Apr 8, 2013
NSString *strurl = [NSString stringWithFormat:@"http://%@",strMediaIconUrl];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:strurl]];
use http:// must.