9

Previously i was using XCode 8 beta 3 and testing it on iOS 10 device. But now i want my app to support previous versions of iOS. When i am trying to run it on iOS 9 device after decreasing the deployment target from project settings, this particular method is showing error since it's only available for iOS 10.0 or newer:

UIApplication.shared().open((url as URL), options: [:], completionHandler: nil)
Rachit Rawat
  • 2,410
  • 3
  • 19
  • 30
  • see this once http://stackoverflow.com/questions/25945324/swift-open-link-in-safari – Anbu.Karthik Aug 02 '16 at 05:30
  • 1
    I think this is a valid question separate from the marked duplicate - in future the other question should probably be updated for iOS 10, whereas this one is specifically about the difference between 10 and previous. (Didn't search to see if there were other dupes, this one was first on google though) – CupawnTae May 10 '17 at 09:03

1 Answers1

28

Use below code as it available in lower versions of iOS

if UIApplication.sharedApplication().canOpenURL(url!) {
   UIApplication.sharedApplication().openURL(url!)
}

Swift 3.0 and above

 // for versions iOS 10 and above
 if UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.open(url, options: [:])
 }

// for versions below iOS 10
if UIApplication.shared.canOpenURL(url) {
   UIApplication.shared.openURL(url)
}
Jahoe
  • 1,666
  • 2
  • 12
  • 27
Mohammed Shakeer
  • 1,446
  • 16
  • 23