iOS webView播放视频禁止弹出

折腾了半天,各种百度,都是说在html的video中加入webkit-playsinline属性,可是怎么都不起作用,后来去Apple查看官方API,人家已经说的很明白了,真是一顿头大啊。

You must set this property to play inline video. Set this property to true to play videos inline. Set this property to false to use the native full-screen controller. When adding a video element to a HTML document on the iPhone, you must also include the playsinline attribute.

Important
Apps created before iOS 10.0 must use the webkit-playsinline attribute.


不废话了,直接上代码

    CGFloat phoneVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (phoneVersion >= 10.0) {
        content = [content stringByReplacingOccurrencesOfString:@"<video" withString:@"<video playsinline"];
    }else {
        content = [content stringByReplacingOccurrencesOfString:@"<video" withString:@"<video webkit-playsinline"];
    }

最后别忘了设置webView的allowsInlineMediaPlayback属性为YES

  webView.allowsInlineMediaPlayback = YES;

猜你喜欢

转载自blog.csdn.net/Lea__DongYang/article/details/88692540