问题
I have a delegate method but it doesn't help me . Please refer to the method below
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
回答1:
What page are you trying to open? UIWebView will NOT auto play any video by default. So if your video dose auto played, it should be some javascript in your HTML let it start to play.
Maybe you should check your HTML first.
回答2:
You can disable auto playback in the webView via code like below. Don't rely on the storyboard options. Didn't work for me. Have to do it in swift.
webView.mediaPlaybackRequiresUserAction = true
webView.allowsInlineMediaPlayback = false
Swift 5:
webView.configuration.mediaTypesRequiringUserActionForPlayback = .all
webView.allowsInlineMediaPlayback = false
webView.configuration.allowsInlineMediaPlayback = false
回答3:
You didn't actually give us your code, but it sounds like inside that method, you should have return NO;
. This tells the delegate method to NOT start.
Also, somewhere (probably where you create your web view), make sure you set the delegate with: myWebView.delegate = self;
.
来源:https://stackoverflow.com/questions/7022579/disable-autoplaying-video-for-uiwebview