1
1
import { Trace } from '../trace' ;
2
- import { dataSerialize , ios as iOSUtils } from './native-helper' ;
2
+ import { ios as iOSUtils } from './native-helper' ;
3
3
4
4
export { clearInterval , clearTimeout , setInterval , setTimeout } from '../timer' ;
5
5
export * from './common' ;
@@ -39,7 +39,7 @@ export function openUrl(location: string): boolean {
39
39
try {
40
40
const url = NSURL . URLWithString ( location . trim ( ) ) ;
41
41
if ( UIApplication . sharedApplication . canOpenURL ( url ) ) {
42
- UIApplication . sharedApplication . openURLOptionsCompletionHandler ( url , dataSerialize ( { } ) , null ) ;
42
+ openUrlAsync ( location ) ;
43
43
return true ;
44
44
}
45
45
} catch ( e ) {
@@ -50,6 +50,25 @@ export function openUrl(location: string): boolean {
50
50
return false ;
51
51
}
52
52
53
+ export function openUrlAsync ( location : string ) : Promise < boolean > {
54
+ return new Promise < boolean > ( ( resolve , reject ) => {
55
+ try {
56
+ const url = NSURL . URLWithString ( location . trim ( ) ) ;
57
+ const app = UIApplication . sharedApplication ;
58
+ if ( app . canOpenURL ( url ) ) {
59
+ app . openURLOptionsCompletionHandler ( url , null , ( success : boolean ) => {
60
+ resolve ( success ) ;
61
+ } ) ;
62
+ } else {
63
+ resolve ( false ) ;
64
+ }
65
+ } catch ( e ) {
66
+ Trace . write ( 'Error in OpenURL' , Trace . categories . Error , Trace . messageType . error ) ;
67
+ reject ( e ) ;
68
+ }
69
+ } ) ;
70
+ }
71
+
53
72
export function isRealDevice ( ) : boolean {
54
73
return iOSUtils . isRealDevice ( ) ;
55
74
}
0 commit comments