將Bigbluebutton框架通過webView打開版本限制提示問題解決

Bigbluebutton 官網(wǎng)文檔:http://docs.bigbluebutton.org/

官方建議PC和手機(jī)使用Chrome或者Firefox、safari瀏覽器打開網(wǎng)頁就可以使用。

問題:現(xiàn)在開發(fā)APP當(dāng)中,用iOS、安卓內(nèi)核的瀏覽器(Webview)打開網(wǎng)頁會提示版本太低。但是手機(jī)瀏覽器是可以正常使用 。

IOS上面從safari11開始也提供webrtc支持了。全部用瀏覽器打開就好了。包括iOS 用SFSafariViewController打開也是可以支持的,但是用webview或者wkwebView打開會提示版本不支持建議用瀏覽器打開的提示;包括安卓的webview也是有相同問題;

iOS和安卓的解決辦法:

iOS端? (wkwebView方式):

- (void)setupWKWebView{

? ? UIButton *clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(150, 250, 100, 50)];

? ? clickBtn.backgroundColor = [UIColor yellowColor];

? ? [clickBtn setTitle:@"點(diǎn)擊WKWeb打開" forState:UIControlStateNormal];

? ? clickBtn.titleLabel.textColor = [UIColor blueColor];

? ? [clickBtn addTarget:self action:@selector(clickWKW:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:clickBtn];

? ? WKWebViewConfiguration *webConfiguration = [WKWebViewConfiguration new];

? ? _webView = [[WKWebView alloc] initWithFrame:[UIScreen mainScreen].bounds configuration:webConfiguration];

? ? _webView.UIDelegate = self;

? ? _webView.navigationDelegate = self;

? ? [self.view addSubview:_webView];

? ? _webView.backgroundColor = [UIColor yellowColor];

? ? //修改agent-serve 關(guān)鍵點(diǎn)!??!

? ? NSString *ua = [NSString stringWithFormat:@"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"];

? ? if (@available(iOS 12.0, *)){

? ? ? ? //由于iOS12的UA改為異步,所以不管在js還是客戶端第一次加載都獲取不到,所以此時(shí)需要先設(shè)置好再去獲取

? ? ? ? NSString *userAgent = [_webView valueForKey:@"applicationNameForUserAgent"];

? ? ? ? NSLog(@"old-agent serve:%@",userAgent);

? ? ? ? NSString *newUserAgent = [NSString stringWithFormat:@"%@%@",userAgent,ua];

? ? ? ? NSLog(@"new-agent serve:%@",newUserAgent);

? ? ? ? [_webView setValue:newUserAgent forKey:@"applicationNameForUserAgent"];

? ? }

? ? [_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {

? ? ? ? NSString *userAgent = result;

? ? ? ? if ([userAgent rangeOfString:ua].location != NSNotFound) {

? ? ? ? ? ? return ;

? ? ? ? }

? ? ? ? NSString *newUserAgent = [userAgent stringByAppendingString:ua];

? ? ? ? NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent,@"UserAgent", nil];

? ? ? ? [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

? ? ? ? [[NSUserDefaults standardUserDefaults] synchronize];

? ? ? ? //不添加以下代碼則只是在本地更改UA,網(wǎng)頁并未同步更改

? ? ? ? if (@available(iOS 9.0, *)) {

? ? ? ? ? ? [self->_webView setCustomUserAgent:newUserAgent];

? ? ? ? } else {

? ? ? ? ? ? [self->_webView setValue:newUserAgent forKey:@"applicationNameForUserAgent"];

? ? ? ? }

? ? }];

//加載請求必須同步在設(shè)置UA的后面

? ? NSURL *url = [NSURL URLWithString:_pathUrl];

? ? NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

? ? [_webView loadRequest:request];

}

安卓端(webview):

安卓代碼加下面的內(nèi)容(似乎是將瀏覽器定義成PC瀏覽器來使用)

WebSettings settings = webView.getSettings();

?settings.setUserAgentString("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36");

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容