Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternate method for UIApplication.shared().open() for iOS 9 and less? [duplicate]

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)
like image 635
Rachit Rawat Avatar asked Aug 02 '16 05:08

Rachit Rawat


1 Answers

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)
}
like image 91
Mohammed Shakeer Avatar answered Oct 19 '22 23:10

Mohammed Shakeer