OpenURL does not open Safari

I am trying to use an action sheet to open a safari with a link. The variable is set correctly and displays the link accordingly, but for some reason Safari will not open, and I cannot understand why ...

Here is 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]]; } } 
+4
source share
2 answers

To open a link in Safari, all you have to do is the following. urlAddress is an NSString that you install where you need it to be installed. Alternatively, you can replace urlAddress with @"someString" .

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlAddress]]; 

Did you also UIActionSheetDelegate that your header file implements the UIActionSheetDelegate protocol?

Edit:

Try the following: "

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != -1) { NSUrl *myURL = [NSURL URLWithString:self.url]; if (![[UIApplication sharedApplication] openURL:myURL]) { NSLog(@"%@%@",@"Failed to open url:",[myURL description]); } } } 
+1
source
 NSString *strurl = [NSString stringWithFormat:@"http://%@",strMediaIconUrl]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strurl]]; use http:// must. 
+15
source

Source: https://habr.com/ru/post/1433077/


All Articles