iOS webView播放视频禁止弹出

67 篇文章 0 订阅
14 篇文章 0 订阅

折腾了半天,各种百度,都是说在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;

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值