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

fix(motion): example code fix to work on ios/android #1614

Closed
wants to merge 3 commits into from
Closed

fix(motion): example code fix to work on ios/android #1614

wants to merge 3 commits into from

Conversation

dtarnawsky
Copy link
Contributor

This resolves ionic-team/capacitor-docs#91

The DeviceMotionEvent.requestPermission API is only present on Safari and iOS. It also needs to be typecast to any in Typescript.

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the capacitor test app we do it like

if (DeviceOrientationEvent !== undefined && typeof DeviceOrientationEvent.requestPermission === 'function')

That way it will still work on javascript as the cast to any code will not work in javascript.
While the block of code is marked as typescript, all other plugins code is javascript "compliant" too.

But we use that code to show or hide a button that's what will actually request the permission, and since this example code comes from the test app, it doesn't include the checks, because you can only get the button click if the button was displayed.

Also, while you have added a comment that says // This should return a result of 'granted', the user could also have rejected the permission, so would be good to check the actual status and do something if not granted.

The test app page for reference:
https://github.com/ionic-team/capacitor-testapp/blob/main/src/pages/Motion.tsx

@giralte-ionic giralte-ionic self-requested a review August 25, 2023 14:47
@dtarnawsky dtarnawsky closed this by deleting the head repository Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error with the configuration of the plugin Motion
4 participants