@@ -29,11 +29,9 @@ class RNCallKeep {
29
29
this . _callkitEventHandlers . delete ( handler ) ;
30
30
} ;
31
31
32
- setup = ( options ) => {
32
+ setup = async ( options ) => {
33
33
if ( ! isIOS ) {
34
- return ( async ( ) => {
35
- return this . _setupAndroid ( options . android ) ;
36
- } ) ( ) ;
34
+ return this . _setupAndroid ( options . android ) ;
37
35
}
38
36
39
37
return this . _setupIOS ( options . ios ) ;
@@ -110,38 +108,44 @@ class RNCallKeep {
110
108
RNCallKeepModule . setCurrentCallActive ( ) ;
111
109
} ;
112
110
113
- _setupIOS = ( options ) => {
111
+ _setupIOS = async ( options ) => new Promise ( ( resolve , reject ) => {
114
112
if ( ! options . appName ) {
115
- throw new Error ( 'RNCallKeep.setup: option "appName" is required' ) ;
113
+ reject ( 'RNCallKeep.setup: option "appName" is required' ) ;
116
114
}
117
115
if ( typeof options . appName !== 'string' ) {
118
- throw new Error ( 'RNCallKeep.setup: option "appName" should be of type "string"' ) ;
116
+ reject ( 'RNCallKeep.setup: option "appName" should be of type "string"' ) ;
119
117
}
120
118
121
- RNCallKeepModule . setup ( options ) ;
122
- } ;
119
+ resolve ( RNCallKeepModule . setup ( options ) ) ;
120
+ } ) ;
123
121
124
122
_setupAndroid = async ( options ) => {
125
123
const hasAccount = await RNCallKeepModule . checkPhoneAccountPermission ( ) ;
126
- if ( hasAccount ) {
127
- return ;
128
- }
129
124
130
- Alert . alert (
131
- options . alertTitle ,
132
- options . alertDescription ,
133
- [
134
- {
135
- text : options . cancelButton ,
136
- onPress : ( ) => { } ,
137
- style : 'cancel' ,
138
- } ,
139
- { text : options . okButton ,
140
- onPress : ( ) => RNCallKeepModule . openPhoneAccounts ( )
141
- } ,
142
- ] ,
143
- { cancelable : true } ,
144
- ) ;
125
+ return new Promise ( ( resolve , reject ) => {
126
+ if ( hasAccount ) {
127
+ return resolve ( ) ;
128
+ }
129
+
130
+ Alert . alert (
131
+ options . alertTitle ,
132
+ options . alertDescription ,
133
+ [
134
+ {
135
+ text : options . cancelButton ,
136
+ onPress : reject ,
137
+ style : 'cancel' ,
138
+ } ,
139
+ { text : options . okButton ,
140
+ onPress : ( ) => {
141
+ RNCallKeepModule . openPhoneAccounts ( ) ;
142
+ resolve ( ) ;
143
+ }
144
+ } ,
145
+ ] ,
146
+ { cancelable : true } ,
147
+ ) ;
148
+ } ) ;
145
149
} ;
146
150
147
151
/*
0 commit comments