ITMS-90809: Deprecated API Usage :WKWebView

1、背景:

最近上传一个新包审核,被拒绝,反馈如下:
ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs . See https://developer.apple.com/documentation/uikit/uiwebview for more information.

具体原因:由于苹果已经弃用 UIWebView,只能使用WKWebView。
我查了项目里使用到 UIWebView 的地方,只有在设置UA的时候使用到。
因此,只要改成WKWebView设置UA即可。

2、解决方案:

AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    delegate.wkbView = [[WKWebView alloc] init];
    [delegate.wkbView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.jianshu.com/"]]];

    [delegate.wkbView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable response, NSError * _Nullable error) {
        //获取系统默认UA
        NSString *defAgent = response;
        //使用新UA
        NSString *newAgent = [defAgent stringByAppendingFormat:@" %@/",@"any string you want to add"];
        newAgent = [newAgent stringByAppendingString:[[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]];
        
        //注册新的UA
        NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
        
        delegate.wkbView = nil;
    }];

3.总结:

由于wkwebview是异步获取到UA,所以在获取到UA之前,wkwebview不能被释放,因此可以将临时用到的wkwebview让appdelegate持有。(在这里的webview只须让某个对象持有即可)。

如果获取到UA为nil,
可能是以下原因:
1、wkwebview未执行loadRequest方法;
2、wkwebview未被其他对象持有而提前释放。

4.排查项目包含uiwebview的文件与静态库

有时候静态库包含uiwebview不方便排查,可使用以下方法:

打开终端控制台,cd 到项目目录,使用脚本排查 grep -r UIWebView . (脚本包含最后一个标点符号)
执行以上代码,会得到项目中具体包含uiwebview 静态库或者文件的名称及相关代码。

脚本执行结果如下:

Binary file ./YHHeYiTong.xcworkspace/xcuserdata/zxl.xcuserdatad/UserInterfaceState.xcuserstate matches
./Pods/Pods.xcodeproj/project.pbxproj:      D89CF19D4A9014D7BACE5208F8520D99 /* UIWebView+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = EED7CBE5C85DDD4AC897159EEAADEC73 /* UIWebView+AFNetworking.h */; settings = {ATTRIBUTES = (Project, ); }; };
./Pods/Pods.xcodeproj/project.pbxproj:      FF9FD2F1C4CAAB541D89012739DA19B3 /* UIWebView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 142B4D8B73732CB078FD85A04E40EED0 /* UIWebView+AFNetworking.m */; settings = {COMPILER_FLAGS = "-w -Xanalyzer -analyzer-disable-all-checks"; }; };
./Pods/Pods.xcodeproj/project.pbxproj:      142B4D8B73732CB078FD85A04E40EED0 /* UIWebView+AFNetworking.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "UIWebView+AFNetworking.m"; path = "UIKit+AFNetworking/UIWebView+AFNetworking.m"; sourceTree = ""; };
./Pods/Pods.xcodeproj/project.pbxproj:      EED7CBE5C85DDD4AC897159EEAADEC73 /* UIWebView+AFNetworking.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIWebView+AFNetworking.h"; path = "UIKit+AFNetworking/UIWebView+AFNetworking.h"; sourceTree = ""; };
./Pods/Pods.xcodeproj/project.pbxproj:              EED7CBE5C85DDD4AC897159EEAADEC73 /* UIWebView+AFNetworking.h */,
./Pods/Pods.xcodeproj/project.pbxproj:              142B4D8B73732CB078FD85A04E40EED0 /* UIWebView+AFNetworking.m */,
./Pods/Pods.xcodeproj/project.pbxproj:              D89CF19D4A9014D7BACE5208F8520D99 /* UIWebView+AFNetworking.h in Headers */,
./Pods/Pods.xcodeproj/project.pbxproj:              FF9FD2F1C4CAAB541D89012739DA19B3 /* UIWebView+AFNetworking.m in Sources */,
./Pods/YHOnePaySDK/YHOnePaySDK/Classes/Common/webview/YHOnePayWebVC.h:@interface YHOnePayWebVC : YHBaseVC
./Pods/YHOnePaySDK/YHOnePaySDK/Classes/Common/helper/YHOnePayHelper.m:            UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
./Pods/WebViewJavascriptBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m:- (void)webViewDidFinishLoad:(UIWebView *)webView {
./Pods/WebViewJavascriptBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m:- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
./Pods/WebViewJavascriptBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m:- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
./Pods/WebViewJavascriptBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.m:- (void)webViewDidStartLoad:(UIWebView *)webView {
./Pods/WebViewJavascriptBridge/WebViewJavascriptBridge/WebViewJavascriptBridge.h:    #import 
./Pods/AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h:    #import "UIWebView+AFNetworking.h"
./Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m:// UIWebView+AFNetworking.m
./Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m:#import "UIWebView+AFNetworking.h"
./Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m:@interface UIWebView (_AFNetworking)
./Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m:@implementation UIWebView (_AFNetworking)
./Pods/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.m:@implementation UIWebView (AFNetworking)
./YHHeYiTong/net/YHUserAgent.m:    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
./YHHeYiTong/module/appointment/view/tableviewcell/YHRegAppointTipCell.m:        UIWebView *view = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 229, 250)];
./YHHeYiTong/module/mine/view/YHHelpContactServiceView.m:                UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
Binary file ./YHHeYiTong/thirdparty/EsscSDK/EsscSDK.framework/EsscSDK matches
Binary file ./.git/index matches

你可能感兴趣的:(ITMS-90809: Deprecated API Usage :WKWebView)