index.uts 653 B

1234567891011121314151617181920
  1. import { OpenSchema, CanOpenURL } from '../interface.uts'
  2. export const openSchema : OpenSchema = function (url : string) : void {
  3. if (canOpenURL(url)) {
  4. let uri = new URL(string = url)
  5. UIApplication.shared.open(uri!, options = new Map<UIApplication.OpenExternalURLOptionsKey, any>(), completionHandler = null)
  6. } else {
  7. console.error('url param Error: ', url)
  8. }
  9. }
  10. export const canOpenURL : CanOpenURL = function (url : string) : boolean {
  11. if (typeof url == 'string' && url.length > 0) {
  12. let uri = new URL(string = url)
  13. if (uri != null && UIApplication.shared.canOpenURL(uri!)) {
  14. return true
  15. }
  16. }
  17. return false
  18. }