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

Error with the configuration of the plugin Motion #91

Open
loicparent opened this issue Oct 12, 2022 · 2 comments
Open

Error with the configuration of the plugin Motion #91

loicparent opened this issue Oct 12, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@loicparent
Copy link

Describe the bug
Hello,
An error appears when I try to set the plugin @capacitor/motion.

To reproduce
Steps to reproduce the behavior:

  1. Install an blank ionic project + add www and ìos`
  2. Install the plugin using these commands: npm install @capacitor/motion npx cap sync
  3. Open the file app.component.ts
  4. Add the imports on the top of the file
  5. In the function ngOnInit(), add the method to request the permission `await DeviceMotionEvent.requestPermission();``
  6. See the error (red underline below requestPermission): Property 'requestPermission' does not exist on type '{ new (type: string, eventInitDict?: DeviceMotionEventInit): DeviceMotionEvent; prototype: DeviceMotionEvent; }'

Screenshot
render

Expected behavior
Don't have any error when I try to setup the plugin following the instructions.

Browser and OS (please complete the following information)

  • OS: MacOs Monterey 12.6
  • Browser: Chrome
  • Version: 105.0.5195.125

Thank you for your help,
Loïc

@loicparent loicparent added the bug Something isn't working label Oct 12, 2022
@loicparent
Copy link
Author

Hello,

I notice that this question was asked in the Ionic forum here.
So it looks like this is not a recent issue. Could you please help us to use this plugin with Ionic?

Thanks,
Loïc

@dtarnawsky
Copy link
Contributor

PR to improve this: ionic-team/capacitor-plugins#1614

Essentially you want to call:

if ((DeviceMotionEvent as any).requestPermission) {
        const result = await (DeviceMotionEvent as any).requestPermission();
        // This should return a result of 'granted'
}

The DeviceMotionEvent.requestPermission API is available on some Safari/Mobile Safari/iOS versions so you need to check if the API exists before calling it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants