Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ISSUE-025

灵犀互娱SDK网页显示问题

常见表现

登录界面、公告界面的网页不显示。

相关源码

var isIOS = /iPad|iPhone|iPod/i.test(navigator.platform) ||
    (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);

原因分析

灵犀互娱SDK通过上面的代码来判断设备是否iOS,如果不是,则不会执行后续代码。

而在Mac上运行的iOS应用,打开网页时默认会请求桌面版网页,这种情况下navigator.platform = "MacIntel",但navigator.maxTouchPoints = 0,不满足上述代码中的条件判断。

解决方法

方法一:修改PlayCover代码,强制请求移动端网页,这种情况下navigator.platform = "iPad"

PlayTools NSObject+Swizzle.m

#import <WebKit/WebKit.h>

- (WKWebView *) hook_WKWebView_initWithFrame:(CGRect) frame
                               configuration:(WKWebViewConfiguration *) config {
    WKWebView *webView = [self hook_WKWebView_initWithFrame:frame configuration:config];
    webView.configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeMobile;
    return webView;
}

[objc_getClass("WKWebView") swizzleInstanceMethod:@selector(initWithFrame:configuration:) withMethod:@selector(hook_WKWebView_initWithFrame:configuration:)];

方法二:在应用数据中查找是否有缓存的网页文件,移除navigator.maxTouchPoints > 1这个条件判断。