Skip to content
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

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

alokpant
Copy link
Contributor

Description

checkIfHasSMSPermission method was sometimes returning true and sometimes returning an object as:

{
      hasReceiveSmsPermission: false/true,
      hasReadSmsPermission: false/true,
}

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)

  1. Makes the data returned from consistent
  2. Adds small documentation to the methods.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

alokpant and others added 2 commits November 29, 2024 12:53
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.
Comment on lines +115 to +125
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);
}
Copy link
Contributor Author

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);
}

Copy link
Contributor Author

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.

Copy link
Owner

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?

@maniac-tech maniac-tech self-assigned this Dec 21, 2024
@maniac-tech maniac-tech added the enhancement New feature or request label Dec 21, 2024
Copy link
Owner

@maniac-tech maniac-tech left a 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.

Comment on lines +115 to +125
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);
}
Copy link
Owner

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?

@maniac-tech
Copy link
Owner

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.

@alokpant : #79

See if you wish to fix it.

@maniac-tech maniac-tech linked an issue Jan 29, 2025 that may be closed by this pull request
@maniac-tech maniac-tech merged commit cfb628b into maniac-tech:master Jan 29, 2025
@maniac-tech
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent data return from checkIfHasSMSPermission
2 participants