问题
<input type="file" capture="camera" accept="image/*">
allows a mobile browser to take a picture. On Android native browser and chrome, clicking the input button launches the camera instantly. On iOS Safari, the button launches an alert asking to "Take Photo" or choose from "Photo Library". How can I launch the native camera immediately?
回答1:
It has to do with who is supporting WebRTC. Currently there is no Safari support, partial support from Chrome on Android, experimental support from Firefox for Android. On Android, the default behavior is to use the front facing camera. Future work will allow us to choose the camera from javascript, but this feature is only experimental in FireFox.
回答2:
It's not possible on iOS at this time.
iOS6 through 10 do not support the capture
attribute which is meant to force the user agent to use the camera, not the "Photo Library".
The capture
attribute is part of HTML Media Capture.
PS: You could improve your code by replacing capture="camera"
with just capture
. In 2012 the capture attribute was changed from 4 strings to boolean in the HTML Media Capture spec.
来源:https://stackoverflow.com/questions/26518344/html5-safari-ios-access-only-camera-not-photo-library