Hi, I would like to open my site from a cell in the viewing table in the safari viewing controller if the user is on iOS 9 or higher. If the user is on iOS 7 or 8, the website should open in the standard Safari application.
This is the code that I am currently using that opens safari.
case 3: { // Follow us section switch (indexPath.row) { case 0: { //Website NSURL *url = [NSURL URLWithString:@"http://www.scanmarksapp.com"]; if (![[UIApplication sharedApplication] openURL:url]) { NSLog(@"%@%@",@"Failed to open url:",[url description]); } } break; default: break; } } break;
I believe that this code should open the safari view controller with my site. But I'm not sure how to combine both sets of code.
- (void)openLink:(NSString *)url { NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.scanmarksapp.com", url]]; if (URL) { SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL]; sfvc.delegate = self; [self presentViewController:sfvc animated:YES completion:nil]; } #pragma Safari View Controller Delegate - (void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller { [controller dismissViewControllerAnimated:YES completion:nil]; }
I understand that this is the code used to determine the version of iOS.
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
I followed your advice
- (void)openLink:(NSString *)url { NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.scanmarksapp.com", url]]; if (URL) { SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL]; sfvc.delegate = self; [self presentViewController:sfvc animated:YES completion:nil]; } else {
Then this code is added under my didSelectRowAtIndexPath table view cell
case 3: { // Follow us section switch (indexPath.row) { case 0: { //Website NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.scanmarksapp.com", url]]; if (URL) { SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL]; sfvc.delegate = self; [self presentViewController:sfvc animated:YES completion:nil]; } else { // will have a nice alert displaying soon. } if ([SFSafariViewController class] != nil) { // Use SFSafariViewController } else { NSURL *url = [NSURL URLWithString:@"http://www.scanmarksapp.com"]; if (![[UIApplication sharedApplication] openURL:url]) { NSLog(@"%@%@",@"Failed to open url:",[url description]); } } } break; default: break; } } break;
I get the error "Use undeclared identifier" in this line of code
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.scanmarksapp.com", url]];
Removing the url at the end of NSStringWithFormat does the work of the Safari view controller. However, on iOS below 9.0, for example. 8.4 application crash.