Last active
March 2, 2018 03:57
-
-
Save lucas34/a9e5a07178a508bc2d5c7009b3c72693 to your computer and use it in GitHub Desktop.
Open url on any Apple os
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
#if os(macOS) | |
import Cocoa | |
#endif | |
#if os(iOS) || os(tvOS) | |
extension URL { | |
public func canOpen() -> Bool { | |
return UIApplication.shared.openURL(self) | |
} | |
public func open() -> Bool { | |
if canOpen() { | |
UIApplication.shared.openURL(self) | |
return true | |
} | |
return false | |
} | |
} | |
#elseif os(macOS) | |
extension URL { | |
public func canOpen() -> Bool { | |
return true | |
} | |
public func open() -> Bool { | |
NSWorkspace.shared().open(self) | |
return true | |
} | |
} | |
#else | |
extension URL { | |
public func canOpen() -> Bool { | |
return false | |
} | |
public func open() -> Bool { | |
return false | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment