iOS 删除Unity中UIWebView

2020-05-09  本文已影响0人  Joshua520

背景介绍

苹果在审核拒约时给出了以下信息:
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 API,尝试使用 Unity 构建一个空工程上传到 TestFlight 或者 QuickSDK
进行预先检查,发现依然存在 UIWebView API 调用。

搜索后发现 Unity 已在 2017.4, 2018.4, 2019.2, 2019.3, 2020.1 中修复,但是旧版本如 Unity 5.6 就不管了:

Unity Issue Tracker – [iOS] Apple throws Deprecated API Usage warning for using UIWebView when submitting Builds to the App Store Connect

解决方案

1、首先将以下内容保存为 URLUtility.mm

#include <iostream>
#import <UIKit/UIKit.h>
using namespace std;
namespace core {
template <class type>
class StringStorageDefault {};
template <class type,class type2>
class basic_string {
public:
char *c_str(void);
};
}
void OpenURLInGame(core::basic_string< char,core::StringStorageDefault<char> > const&arg){}
void OpenURL(core::basic_string<char,core::StringStorageDefault<char> >const&arg){
const void *arg2= &arg;
UIApplication *app = [UIApplication sharedApplication];
NSString *urlStr = [NSString stringWithUTF8String:(char *)arg2];
NSURL *url = [NSURL URLWithString:urlStr];
[app openURL:url];
}
void OpenURL(std::string const&arg){
UIApplication *app = [UIApplication sharedApplication];
NSString *urlStr = [NSString stringWithUTF8String:arg.c_str()];
NSURL *url = [NSURL URLWithString:urlStr];
[app openURL:url];
}

2、查看libiPhone-lib.a支持那些架构

file libiPhone-lib.a
libiPhone-lib.a: Mach-O universal binary with 3 architectures: [arm_v7:current ar archive] [arm64] [arm_v7s]
libiPhone-lib.a (for architecture armv7):   current ar archive
libiPhone-lib.a (for architecture arm64):   current ar archive
libiPhone-lib.a (for architecture armv7s):  current ar archive

3、编译对应架构的URLUtility.o

//arm64
clang -c URLUtility.mm -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
//armv7s
clang -c URLUtility.mm  -arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
//armv7
clang -c URLUtility.mm  -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk

⚠️不能同时编译3种架构,fouz不能移除

ar -d /Users/eddy/Desktop/lib/libiPhone-lib.a URLUtility.o
ar: /Users/eddy/Desktop/lib/libiPhone-lib.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: /Users/eddy/Desktop/lib/libiPhone-lib.a: Inappropriate file type or format

注意: -isysroot
指定的 SDK 路径一定是当前工程使用的 Xcode 版本,特别是当机器上存在多个 Xcode 版本时要注意。

4、分离lipo libiPhone-lib.a中每个架构的.a

 lipo libiPhone-lib.a -thin armv7 -output libiPhone-lib_armv7.a

5、替换对应分离出来架构的.o
确保

//删除原有的 URLUtility.o
ar -d libiPhone-lib_armv7.a URLUtility.o
//在文件最后增加 URLUtility.o
ar -q libiPhone-lib_armv7.a URLUtility.o

6、合并替换后的.a

//合并armv7和armv7s
lipo -create libiPhone-lib_arm64.a libiPhone-lib_armv7.a libiPhone-lib_armv7s.a -output libiPhone-lib_new.a 
//合并arm64和上面的合并
lipo -create libiPhone-lib_new.a  libiPhone-lib_arm64.a  -output libiPhone-lib_w.a 

7、用合并后的替换之前的.a,解决问题

确保libiPhone-lib.a、URLUtility.mm及shell文件在同一目录下
直接执行

#!/bin/bash

iPhone_OS_SDK_path="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
arm64_path="./URLUtility64/"
armv7_path="./URLUtilityv7/"
armv7s_path="./URLUtilityv7s/"
new_lib_path="./new"

mkdir $arm64_path
mkdir $armv7_path
mkdir $armv7s_path
mkdir $new_lib_path

clang -c URLUtility.mm -arch arm64 -isysroot $iPhone_OS_SDK_path
mv URLUtility.o ./URLUtility64/URLUtility.o

clang -c URLUtility.mm -arch armv7 -isysroot $iPhone_OS_SDK_path
mv URLUtility.o ./URLUtilityv7/URLUtility.o

clang -c URLUtility.mm -arch armv7s -isysroot $iPhone_OS_SDK_path
mv URLUtility.o ./URLUtilityv7s/URLUtility.o

lipo libiPhone-lib.a -thin arm64 -output ./URLUtility64/libiPhone-lib64.a
lipo libiPhone-lib.a -thin armv7 -output ./URLUtilityv7/libiPhone-libv7.a
lipo libiPhone-lib.a -thin armv7s -output ./URLUtilityv7s/libiPhone-libv7s.a

ar -d ./URLUtility64/libiPhone-lib64.a URLUtility.o
ar -d ./URLUtilityv7/libiPhone-libv7.a URLUtility.o
ar -d ./URLUtilityv7s/libiPhone-libv7s.a URLUtility.o

ar -q ./URLUtility64/libiPhone-lib64.a ./URLUtility64/URLUtility.o
ar -q ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7/URLUtility.o
ar -q ./URLUtilityv7s/libiPhone-libv7s.a ./URLUtilityv7s/URLUtility.o

lipo -create ./URLUtility64/libiPhone-lib64.a ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7s/libiPhone-libv7s.a -output $new_lib_path/libiPhone-lib.a

8、查看是否包含UIWebView

find . | grep -v .svn  | grep "\.a" | grep -v "\.app" | xargs grep UIWebView

上一篇下一篇

猜你喜欢

热点阅读