fricko
fricko

Reputation: 243

Ionic 5 / capacitor @capacitor/motion persist DeviceMotionEvent.requestPermission

I have a problem in iOS and Ionic.

I develope an Ionic app and I want to use the motion plugin. I need the direction of the Smartphone to show the user where he is looking. I got this to work when I created an alert, which forced a click and the the prompt appears, to allow the motion permissions. For that I use the DeviceMotionEvent.requestPermission() function. But this permission seems not to be saved. On the next app start (removed from task and started new instance) the permission are not there and the user has to grant the permission again.

So my questions are:

  1. Is there a way to save this permission like all other permissions like e.g.location? I searched a whole day in the www but found nothing like that.

The next problem then is to be able to check, if the permission is already granted to be able to skip the annoying alert and following prompt. Is there a way to check the permission without calling the requestPermission() function? I hope you can help me here. Thanx

Upvotes: 0

Views: 663

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

Sadly it’s a bug on WKWebView, I reported it to Apple long ago.

They have not fixed it, but for iOS 15 they have provided a WKUIDelegate that will prevent the prompt. I’ve sent a pull request to add the delegate https://github.com/ionic-team/capacitor/pull/5317 It also needs NSMotionUsageDescription In the Info.posit

https://developer.apple.com/documentation/bundleresources/information_property_list/nsmotionusagedescription

But that will only fix the problem for iOS 15 and only if using Xcode 13 to build, on iOS 13-14 will keep prompting every time.

Upvotes: 1

Related Questions