Skip to content

Commit 753d2ba

Browse files
authored
Merge pull request #12 from wazo-pbx/allow_check_permissions
Allow check permissions
2 parents 429c0e5 + abf2804 commit 753d2ba

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

docs/android-installation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class MainActivity extends ReactActivity {
4444
// Permission results
4545
@Override
4646
public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults) {
47+
super.onRequestPermissionsResult(permsRequestCode, permissions, grantResults);
4748
switch (permsRequestCode) {
4849
case RNCallKeepModule.REQUEST_READ_PHONE_STATE:
4950
RNCallKeepModule.onRequestPermissionsResult(grantResults);

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)