-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update indexjs to return same result and add documentation #76
Conversation
checkIfHasSMSPermission method was sometimes returning true and sometimes returning an object as: ``` { hasReceiveSmsPermission: false/true, hasReadSmsPermission: false/true, } ``` this now makes it consistent so that it always returns the hash.
const status = await PermissionsAndroid.requestMultiple([ | ||
PermissionsAndroid.PERMISSIONS.RECEIVE_SMS, | ||
PermissionsAndroid.PERMISSIONS.READ_SMS, | ||
]); | ||
|
||
if (status === PermissionsAndroid.RESULTS.GRANTED) return true; | ||
if (status === PermissionsAndroid.RESULTS.DENIED) { | ||
console.log("Read Sms permission denied by user.", status); | ||
} else if (status === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) { | ||
console.log("Read Sms permission revoked by user.", status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from what I have seen, status in this case would return
{
"android.permission.RECEIVE_SMS": "granted",
"android.permission.READ_SMS": "denied"
}
so status === PermissionAndroid.RESULTS.GRANTED
would be checking text against an object.
this can be rewritten as:
const status = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
PermissionsAndroid.PERMISSIONS.READ_SMS,
]);
const granted = PermissionsAndroid.RESULTS.GRANTED;
const denied = PermissionsAndroid.RESULTS.DENIED;
const neverAskAgain = PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN;
if (status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS] === granted &&
status[PermissionsAndroid.PERMISSIONS.READ_SMS] === granted) {
return true;
}
if ([status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS], status[PermissionsAndroid.PERMISSIONS.READ_SMS]].includes(denied)) {
console.log("Read/Receive SMS permission denied by user.", status);
} else if ([status[PermissionsAndroid.PERMISSIONS.RECEIVE_SMS], status[PermissionsAndroid.PERMISSIONS.READ_SMS]].includes(neverAskAgain)) {
console.log("Read/Receive SMS permission revoked by user.", status);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am new to mobile development, so would lack knowledge if this is same for all devices. I only tested with what is available to me, and it returns in that case an object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your assumption might be right in this case. Can you cross check with official android documentation too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from https://github.com/maniac-tech/react-native-expo-read-sms/pull/76/files#r1863434353 rest everything looks good.
Will convert the link into an issue and release the other set of changes.
const status = await PermissionsAndroid.requestMultiple([ | ||
PermissionsAndroid.PERMISSIONS.RECEIVE_SMS, | ||
PermissionsAndroid.PERMISSIONS.READ_SMS, | ||
]); | ||
|
||
if (status === PermissionsAndroid.RESULTS.GRANTED) return true; | ||
if (status === PermissionsAndroid.RESULTS.DENIED) { | ||
console.log("Read Sms permission denied by user.", status); | ||
} else if (status === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) { | ||
console.log("Read Sms permission revoked by user.", status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your assumption might be right in this case. Can you cross check with official android documentation too?
See if you wish to fix it. |
Released the version: https://github.com/maniac-tech/react-native-expo-read-sms/releases/tag/v9.0.0-alpha |
Description
checkIfHasSMSPermission method was sometimes returning true and sometimes returning an object as:
This also aligns to the documentation which states that it returns a hash. https://github.com/maniac-tech/react-native-expo-read-sms/blob/master/README.md?plain=1#L49
this now makes it consistent so that it always returns the hash.
Fixes # (issue)
Type of change