Comments (12)
Motion plugin just uses the web implementation.
On iOS 13 Apple requires to prompt the user for permission.
You can call DeviceOrientationEvent.requestPermission();
(has to be from an user gesture like button click, otherwise the prompt won't appear)
from capacitor-plugins.
@SimonScholl - could you not just prompt the user with a quick explanation alert / dialog and then the tap event on "OK" would trigger the permission prompt? Lots of other apps do this with push notification prompts.
from capacitor-plugins.
You only have to request the permission iOS 13, on iOS 12 it will still work without any changes.
In your own code, the if (typeof (DeviceOrientationEvent as any).requestPermission === 'function')
will only be true on iOS 13, on Android and iOS 11-12 will be false, in those cases don't show the button for the permission prompting.
from capacitor-plugins.
Just wanted to say, that i share the same experience.
from capacitor-plugins.
Motion plugin just uses the web implementation.
On iOS 13 Apple requires to prompt the user for permission.
You can callDeviceOrientationEvent.requestPermission();
(has to be from an user gesture like button click, otherwise the prompt won't appear)
I can confirm i was able to access the motion api again with integrating the DeviceOrientationEvent.requestPermission();
. I use plain js in my Angular/Ionic App like that:
if (typeof (DeviceOrientationEvent as any).requestPermission === 'function') {
(DeviceOrientationEvent as any).requestPermission().then(permissionState => {
if (permissionState === 'granted') {
// do something
}
}).catch(console.error);
}
The problem i have is that i want to check this when my app is getting launched. From these sources
https://www.w3.org/TR/orientation-event/#permission
https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation
i know that i can only request the permissions with an user interaction. So i thought i create a hidden button which i trigger with an dom element click call after my component was loaded. But so far no success.
from capacitor-plugins.
@SimonScholl - could you not just prompt the user with a quick explanation alert / dialog and then the tap event on "OK" would trigger the permission prompt? Lots of other apps do this with push notification prompts.
Would be one solution, after some time i decided to stick to the specification. The problem i see is the behavior on lower iOS versions. Especially iOS 12 blocked the usage of the deviceorientation web api, the problem is safari would still tell you that it has the browser support, so how to proof if the sensor is available?
My plan was to gather some event callbacks in the background to see if data arrives. If not something is wrong, but on iOS 13 i would have to ask for the permissions before doing that.
from capacitor-plugins.
Motion plugin just uses the web implementation.
On iOS 13 Apple requires to prompt the user for permission.
You can callDeviceOrientationEvent.requestPermission();
(has to be from an user gesture like button click, otherwise the prompt won't appear)
What happens on iOS 12 then? Will the plugin not work at all? Because they blocked DeviceOrientationAPI access out of security reasons in safari. Is this a factor for the ionic native webview as well?
from capacitor-plugins.
I had the same problem, and it even broke for me on iOS 12. I had it working on both versions, but it is still full of HUGE issues. If a user accidentally clicked 'Deny', their phone never prompted them again and even resetting the entire phone's permissions didn't bring back the ability to use the motion data.
Instead of waiting for Apple to figure this out, I started writing a replacement plugin (gist) in swift to access the device's motion data through native APIs and convert them to the Web API equivalent (alpha, beta, gamma, and acceleration w/ gravity).
https://gist.github.com/thomhines/a31f8a33b7bc28dfc55381be3b91dd60
NOTE: I wasn't able to figure out how to get the math right for the 'beta' value, but I didn't need that for my app, so I just left it. Maybe the other values are wrong, too. If someone wants to fork the code to fix the calculations and convert it to a legit Capacitor plugin, they have my blessing and respect!
from capacitor-plugins.
it wont work with live reload either
from capacitor-plugins.
since you have to get permission on user input so you do something like this:
window.document.onclick = function () {
if (
typeof (DeviceMotionEvent as any).requestPermission()
.requestPermission === "function"
) {
(DeviceMotionEvent as any)
.requestPermission()
.then((permissionState) => {
if (permissionState === "granted") {
//do something
}
})
.catch(console.error);
} else {
// handle regular non iOS 13+ devices
//do something
}
};
from capacitor-plugins.
I've created a new issue for using native code in motion plugin, so I'm going to close this one in favor of the other one since the only way of not needing to request the permission would be to use native code
#1192
from capacitor-plugins.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.
from capacitor-plugins.
Related Issues (20)
- [splash-screen] Make docs usable for iOS app HOT 2
- Cannot select a printer from the Share dialogue box HOT 1
- bug(@capacitor/share): FATAL EXCEPTION java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tvoydnevnik/com.tvoydnevnik.MainActivity}: java.lang.SecurityException: com.tvoydnevnik: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts HOT 2
- Add Capacitor Webview HOT 2
- Add map events to be handled at client side HOT 2
- [Bug]: @capacitor/camera - Console (F12) error (undefined) clicking on the camera icon when still loading the camera or not alowing the permission yet. HOT 3
- Complience with Apples Required Reason API HOT 18
- google.maps.Marker is deprecated HOT 1
- [Geolocation / Android] The GPS position is only updated every 5 seconds when using "watchPosition" function on Android HOT 1
- [Feature] Deep linking for Chromebook Android (App appUrlOpen)
- @capacitor/share not work in android 14, capacitor 6 HOT 4
- feat(@capacitor/device) Request to update device plugin to remove privacy-impacting APIs HOT 1
- @capacitor/browser add a new BROWSER_CLOSED event HOT 1
- [@capacitor/filesystem] Successful Filesystem.requestPermissions prompt never resolves due to missing case in callback HOT 5
- [Feature]: native camera max weight settings
- @capacitor/share not working with capacitor v6 HOT 2
- Filesystem.copy not working con content:/ android
- Android 14 targetted build fails with RECEIVER_EXPORTED variable error HOT 2
- Feature Request: Add support for reading files in chunks
- Camera - taking a photo with .getPhoto() in macOs is having delays
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capacitor-plugins.