js判斷iOS平臺(tái)代碼為:
function isIOSApp ()
{
var U = navigator.userAgent.toLowerCase()
var reg = /ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/
console.log('index.html', reg.exec(U))
return !!reg.exec(U) && !!window.webkit && !!window.webkit.messageHandlers
};
但你會(huì)發(fā)現(xiàn)在iPad上為false。
那么我們把userAgent打印出來(lái)看看是個(gè)什么東西:

企業(yè)微信截圖_e279e8e9-fd02-481a-a6bc-dafadff798fb.png
好家伙是Macintosh。
那么我們?cè)趺唇鉀Q這個(gè)問(wèn)題呢?
解決方案:
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
if (@available(iOS 13.0, *))
{
configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeMobile;
}
再打印看看userAgent是個(gè)什么東西:

企業(yè)微信截圖_7d49550d-3e3d-43a2-9356-11a4f3b6761d.png
看到iPad,這就對(duì)了,此時(shí)代碼返回true。