Closed minhchienwikipedia closed 4 years ago
TLDR: Unfortunately this is the default behaviour from iOS, check workaround.
Apple restricts basically every permission authorization in a similar way. The first time you call the method you will receive false
which implicates "User has not been asked for permissions" and any subsequent call will return true
, meaning "User has been asked for permissions".
Basically every iOS app developer (no matter Swift/ObjC or React Native) faces that issue, but it's Apple's way to restrict this popup screen you have on the screenshot.
I'm currently using this flow and it's basically what everyone does in a way.
Check if user has been asked for permissions
const hasBeenAsked = await Fitness.isAuthorized(permissions)
Request permissions, if you can
if (! hasBeenAsked) {
await Fitness.requestPermissions(permissions)
}
Check if you can get some data
const stepsYesterday = await Fitness.getSteps({
startDate: moment().subtract(1, 'day').format(),
endDate: moment().format(),
})
if (stepsYesterday.length === 0) {
...
}
This implicates some issue, it might be user has no data for that period, or has not shared permissions with your app.
At this point, most apps show a popup alert or a styled modal window instructing the user what to do.
Which is:
Side note: For me this doesn't work on a simulator, getting constant spinning loader in Apps screen.
All is good, no need to worry.
Dealing with this is a small pain for the developer, but big pain for the user. Unfortunately I didn't find a better workaround and I'm not sure there is another one.
What can I suggest is that you perform that check on every app start and/or state change (when app goes to background and then active again), because the users can disable this the same way you told them to enable it.
Also, you can take a look and inspiration from other fitness apps and how they handle this kind of situation.
Hope this helps!
@dmitov Thanks for your help! I think that is the only way to check permission on iOS!
When I'm tried using
requestPermissions
on iOS I'm getting issue it's always return true. When the user clickDon't Allow
it shows up an alert like this and then returntrue
. After that, I tried using functionisAuthorized
and it always returnstrue
.Anyone can help me resolve this issue?