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

Usage of Motion Sensors with InAppLocalHostServer #838

Open
aatmmr opened this issue May 11, 2021 · 4 comments
Open

Usage of Motion Sensors with InAppLocalHostServer #838

aatmmr opened this issue May 11, 2021 · 4 comments

Comments

@aatmmr
Copy link

aatmmr commented May 11, 2021

First of all, thank you for creating this package which is highly useful and flexible.

We would like to run a simple HTML5 game in the WebView which is loaded via InAppLocalHostServer. The game uses motion sensors as user controls which works prior to iOS 14 without any issues. Since iOS 14, the user must consent the sensor usage. Using permission_handler requesting the constent works but does not apply to the game running on the localhost. If we add a separate permission request to the game itself, an alert will show up asking:

"localhost" Would Like To Access Motion and Orientation.

Giving consent to the usage will make the game work - so far so good.

However, for a better UX, is it possible to:

  • Change "localhost" or the consent request to a custom text?
  • Pass the consent somehow to the localhost instance, such as, for camera or microphone as described in package docs?

Or am I missing something?

The app runs on package version 5.3.0 and flutter stable branch.

@github-actions
Copy link

👋 @aatmmr

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

@kuhnroyal
Copy link

I also can't get motion events to work for a page server from a local file. But I think this is related to InAppWebView and not InAppLocalHostServer.

There is this https://bugs.webkit.org/show_bug.cgi?id=203287 saying that the WKUIDelegate needs to be set, but I think it is set.

There are also these new delegate methods for iOS 15: https://developer.apple.com/documentation/webkit/wkuidelegate?changes=latest_minor&language=objc

@kuhnroyal
Copy link

Hacking this into InAppWebView.swift:

    @available(iOS 15.0, *)
    public func webView(_ webView: WKWebView,
           requestDeviceOrientationAndMotionPermissionFor origin: WKSecurityOrigin,
                initiatedByFrame frame: WKFrameInfo,
                 decisionHandler: @escaping (WKPermissionDecision) -> Void) {
         decisionHandler(.grant)
     }

And combining it with some javascript after user interaction seems to work:

    DeviceMotionEvent.requestPermission().then(response => {
        console.log(response)
    }).catch(console.error);

Just need some way to remember this permission. Currently I need to grant it again every time the app is started.

kuhnroyal added a commit to kuhnroyal/flutter_inappwebview that referenced this issue Aug 5, 2022
* allow configuration of `requestDeviceOrientationAndMotionPermissionFor` for webview
kuhnroyal added a commit to kuhnroyal/flutter_inappwebview that referenced this issue Aug 5, 2022
* allow configuration of `requestDeviceOrientationAndMotionPermissionFor` for webview
@kuhnroyal
Copy link

I added a PR which allows to support this on iOS 15+.
I have not found a way to do this for older versions (13/14).

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 a pull request may close this issue.

2 participants