index.uts 648 B

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