Skip to content

Commit 80ad5d7

Browse files
committed
Allow to check for permissions
1 parent 24849c4 commit 80ad5d7

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

index.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ class RNCallKeep {
2929
this._callkitEventHandlers.delete(handler);
3030
};
3131

32-
setup = (options) => {
32+
setup = async (options) => {
3333
if (!isIOS) {
34-
return (async () => {
35-
return this._setupAndroid(options.android);
36-
})();
34+
return this._setupAndroid(options.android);
3735
}
3836

3937
return this._setupIOS(options.ios);
@@ -110,38 +108,44 @@ class RNCallKeep {
110108
RNCallKeepModule.setCurrentCallActive();
111109
};
112110

113-
_setupIOS = (options) => {
111+
_setupIOS = async (options) => new Promise((resolve, reject) => {
114112
if (!options.appName) {
115-
throw new Error('RNCallKeep.setup: option "appName" is required');
113+
reject('RNCallKeep.setup: option "appName" is required');
116114
}
117115
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"');
119117
}
120118

121-
RNCallKeepModule.setup(options);
122-
};
119+
resolve(RNCallKeepModule.setup(options));
120+
});
123121

124122
_setupAndroid = async (options) => {
125123
const hasAccount = await RNCallKeepModule.checkPhoneAccountPermission();
126-
if (hasAccount) {
127-
return;
128-
}
129124

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+
});
145149
};
146150

147151
/*

0 commit comments

Comments
 (0)