iOS Question iOS Camera from WebView

Nicolás Cieri

Active Member
Licensed User
Hello,

In my app, I am requesting the permission to the camera from a web.

The app does ask me for permission to allow the camera, but once I say yes, it does nothing.

If I test the web directly in the browser it works.

Something inside the B4i is missing for me.


For B4a, i fixed it with this lines...
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}


But I need it in B4i

Some idea?

Thanks
 

JordiCP

Expert
Licensed User
Longtime User
Did you add the needed NSCameraUsageDescription (and possibly NSMicrophoneUsageDescription) #PlisExtra's?
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
Thanks JordiCP, I have the two #PlisExtra's, and is not working, I can't see the camera on the app.

Once I hit allow access to the camera, it does nothing.

The same thing happened to me on Android, but I had solved it with that code that I mentioned to you.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I could play a bit with it. seems that the WKWebView 'default' config doesn't allow for inline Media
  • The config property to be changed is "allowsInlineMediaPlayback (from HERE)
  • And the way to change the B4i webView configuration from HERE (latest post)

If you are adding the Webview by code, this snippet contains all the needed info. If you are loading the webView in a layout, you should proceed as it is done in the 2nd link's latest post ( remove webview from parent, initializecustom, and add again). Tested, works
B4X:
    Dim conf As NativeObject
    conf = conf.Initialize("WKWebViewConfiguration").RunMethod("new", Null)
    conf.SetField("allowsInlineMediaPlayback", 1)            '<- This is the line that makes the difference
    WV.InitializeWithCustomConfiguration("WV", conf)
    mParent.AddView(WV,0,0,width,height)        
    WV.LoadUrl("https://webrtc.github.io/samples/src/content/devices/input-output/")
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
Hello, thank you very much for your answer.

I've implemented it but it still doesn't work.

Apparently this was not the solution.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It's strange. Without the hack I get a black frame and with it, it works
In my case I am adding the wwebView by code.
I have iOS 15.4.1 but I don't think that it will make any difference.

If you can post or send me a small project where it doesn't work, I'll check it. I'm sure it must be a small detail somewhere.
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
I added it dynamically, not even the link I sent you works for me.

B4X:
        Dim conf As NativeObject
        conf = conf.Initialize("WKWebViewConfiguration").RunMethod("new", Null)
        conf.SetField("allowsInlineMediaPlayback", 1)            '<- This is the line that makes the difference       
        WebView1.InitializeWithCustomConfiguration("WebView1", conf)       
        
        Panel1.RemoveAllViews
        Panel1.AddView(WebView1, 0, 0, Panel1.Width, Panel1.Height)
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Yesterday's test was with a big project of mine that I had opened at that moment. Here you are a small example with just the Web+cam
You'll need to update the package name, certificate and provisioningProfile with your own values
 

Attachments

  • webViewCam.zip
    2.5 KB · Views: 242
Upvote 0

Nicolás Cieri

Active Member
Licensed User
Even in your example you can't see the camera.

It does not work for me.

If I try your link directly in Chrome, it doesn't work either.

If I try it directly in Safari, it works.

But definitely in B4i it doesn't work for me.

Check the attached image.
 

Attachments

  • WhatsApp Image 2022-08-05 at 12.02.07 PM.jpeg
    44.9 KB · Views: 215
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Well, it works correctly for me, so I don't know why it doesn't for you.
I'm using an iPhone XS with iOS 15.4.1
B4i 7.80 with Local Builder

Perhaps there is some setting (specific to iOS16 or not) that must be taken into account? just guessing.



 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
Thanks for the guide, however I think that in B4i, it should be working with the example that Jordi provided, however it was not, if you have any additional recommendations it would be great.

Or someone who has experienced this problem?

Perhaps Erel himself, will there be any other solution?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Might be related. iOS 16 is in beta stage: as such, problems may appear, and not necessarily with all models.

From HERE



Worth checking if this is the case and if available, update to a newest beta to check if they fixed the issue. Or, in the worst case, you can downgrade to iOS 15.6 until iOS16 is stable.


In other posts, they talk about VoiceOver (from accessibility settings) being active (which can happen after an OS upgrade) can interfere with camera usage.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…