2016-07-11 33 views
-1

Safari瀏覽器我有這樣的代碼在Safari中打開網址:打開NSURL在iOS8上

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]]; 

但它只是iOS9適用於,並iOS8上這是行不通的。任何人都知道這可能是什麼?

感謝

+0

定義 「不工作」。 「不起作用」對任何人都沒有幫助。 – Fogmeister

+0

你在哪裏測試設備或模擬器和哪個xcode版本? –

回答

0

您應該使用SFSafariViewController爲iOS 9.還使用https,而不是http。在設備中測試。

if ([SFSafariViewController class] != nil) { 
     SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL]; 
     sfvc.delegate = self; 
     [self presentViewController:sfvc animated:YES completion:nil]; 
    } else { 
     if (![[UIApplication sharedApplication] openURL:URL]) { 
      //NSLog(@"%@%@",@"Failed to open url:",[URL description]); 
     } 
    } 
3

目標C

NSURL *url = [NSURL URLWithString:@"some url"]; 
if ([[UIApplication sharedApplication] canOpenURL:url]) { 
    [[UIApplication sharedApplication] openURL:url]; 
}