问题 2020年5月以来,上传到iTunes Connect的ipa文件如包含UIWebView相关引用,会导致ipa包无法通过处理,构建版本不可用。
审核团队在邮件中给出的说明如下:
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.
使用find
查找工程中相关API:
1 find . | grep -v .svn | grep "\.a" | grep -v "\.app" | xargs grep UIWebView
结果指向libiPhone-lib.a文件,该文件是Unity导出工程时生成的系统库文件,说明其中包含UIWebView引用。
解决方案 方案一 升级Unity版本 Unity在Unity2017.4.33版本中修复了此问题,条件允许可升级Unity版本来解决。
iOS:Fixed Deprecated API Usage warning for using UIWebView when submitting Builds to the App Store Connect.(1180664, 1182274)
方案二 去除libiPhone-lib.a中UIWebView的引用
首先,生成一个URLUtility.mm文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #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 * str; basic_string( char * arg){ str = arg; } }; } 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.str; UIApplication *app = [UIApplication sharedApplication]; NSString *urlStr = [NSString stringWithUTF8String:(char *)arg2]; NSURL *url = [NSURL URLWithString:urlStr]; if (@available(iOS 10.0 , *)) { [app openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey : @YES} completionHandler:nil]; } else { [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]; if (@available(iOS 10.0 , *)) { [app openURL:url options:@{UIApplicationOpenURLOptionsSourceApplicationKey : @YES} completionHandler:nil]; } else { [app openURL:url]; } }
使用lipo查看libiPhone-lib.a文件中包含的架构
1 2 lipo -info libiPhone-lib.a Architectures in the fat file: libiPhone-lib.a are: armv7 arm64 armv7s
可知,以上libiPhone-lib.a中包含的架构有armv7、arm64和armv7s,以下以arm64为例。
使用URLUtility.mm生成对应架构下URLUtility.o文件
1 clang -c URLUtility.mm -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
分离libiPhone-lib.a中各架构文件
1 lipo libiPhone-lib.a -thin arm64 -output ./URLUtility64/libiPhone-lib64.a
移除对应架构中的原有URLUtility.o文件
1 ar -d ./URLUtility64/libiPhone-lib64.a URLUtility.o
将新生成的URLUtility.o文件添加到对应架构的.a中
1 ar -q ./URLUtility64/libiPhone-lib64.a ./URLUtility64/URLUtility.o
将各架构的.a文件合并生成新的libiPhone-lib.a
1 lipo -create ./URLUtility64/libiPhone-lib64.a ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7s/libiPhone-libv7s.a -output ./new/libiPhone-lib.a
以上,即可替换libiPhone-lib.a中的URLUtility.o文件,从而达到移除UIWebView相关引用的目的。
可以使用Python3将以上流程用脚本实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 import osimport shutildef restructure () : 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" if os.path.exists(arm64_path): print("------移除原URLUtility64文件------" ) shutil.rmtree(arm64_path) os.makedirs(arm64_path) if os.path.exists(armv7_path): shutil.rmtree(armv7_path) print("------移除原URLUtilityv7文件------" ) os.makedirs(armv7_path) if os.path.exists(armv7s_path): shutil.rmtree(armv7s_path) print("------移除原URLUtilityv7s文件------" ) os.makedirs(armv7s_path) if os.path.exists(new_lib_path): shutil.rmtree(new_lib_path) print("------移除原new文件------" ) os.makedirs(new_lib_path) cmd_generate_o_arm64 = "clang -c URLUtility.mm -arch arm64 -isysroot " + iPhone_OS_SDK_path cmd_generate_o_armv7 = "clang -c URLUtility.mm -arch armv7 -isysroot " + iPhone_OS_SDK_path cmd_generate_o_armv7s = "clang -c URLUtility.mm -arch armv7s -isysroot " + iPhone_OS_SDK_path cmd_thin_arm64 = "lipo libiPhone-lib.a -thin arm64 -output ./URLUtility64/libiPhone-lib64.a" cmd_thin_armv7 = "lipo libiPhone-lib.a -thin armv7 -output ./URLUtilityv7/libiPhone-libv7.a" cmd_thin_armv7s = "lipo libiPhone-lib.a -thin armv7s -output ./URLUtilityv7s/libiPhone-libv7s.a" cmd_mv_arm64 = "mv URLUtility.o ./URLUtility64/URLUtility.o" cmd_mv_armv7 = "mv URLUtility.o ./URLUtilityv7/URLUtility.o" cmd_mv_armv7s = "mv URLUtility.o ./URLUtilityv7s/URLUtility.o" cmd_delete_arm64 = "ar -d ./URLUtility64/libiPhone-lib64.a URLUtility.o" cmd_delete_armv7 = "ar -d ./URLUtilityv7/libiPhone-libv7.a URLUtility.o" cmd_delete_armv7s = "ar -d ./URLUtilityv7s/libiPhone-libv7s.a URLUtility.o" cmd_add_arm64 = "ar -q ./URLUtility64/libiPhone-lib64.a ./URLUtility64/URLUtility.o" cmd_add_armv7 = "ar -q ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7/URLUtility.o" cmd_add_armv7s = "ar -q ./URLUtilityv7s/libiPhone-libv7s.a ./URLUtilityv7s/URLUtility.o" cmd_create_lib = "lipo -create ./URLUtility64/libiPhone-lib64.a ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7s/libiPhone-libv7s.a -output " + new_lib_path + "/libiPhone-lib.a" print("------处理arm64架构------" ) os.system(cmd_generate_o_arm64) os.system(cmd_thin_arm64) os.system(cmd_mv_arm64) os.system(cmd_delete_arm64) os.system(cmd_add_arm64) print("------处理armv7架构------" ) os.system(cmd_generate_o_armv7) os.system(cmd_thin_armv7) os.system(cmd_mv_armv7) os.system(cmd_delete_armv7) os.system(cmd_add_armv7) print("------处理armv7s架构------" ) os.system(cmd_generate_o_armv7s) os.system(cmd_thin_armv7s) os.system(cmd_mv_armv7s) os.system(cmd_delete_armv7s) os.system(cmd_add_armv7s) os.system(cmd_create_lib) print("🍀生成新的libiPhone-lib.a,已移除UIWebView引用" ) if __name__ == "__main__" : restructure()
初始文件目录为:
1 2 3 . ├── URLUtility.mm └── libiPhone-lib.a
脚本运行完成后文件目录为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 . ├── URLUtility.mm ├── URLUtility64 │ ├── URLUtility.o │ └── libiPhone-lib64.a ├── URLUtilityv7 │ ├── URLUtility.o │ └── libiPhone-libv7.a ├── URLUtilityv7s │ ├── URLUtility.o │ └── libiPhone-libv7s.a ├── libiPhone-lib.a ├── new │ └── libiPhone-lib.a └── restructure.
其中new文件目录下的libiPhone-lib.a已实现UIWebView引用的移除,使用find
命令进行验证,发现新的libiPhone-lib.a中已不包含UIWebView相关任何代码。将该文件与工程中的对应文件进行替换,即可解决ipa包上传问题。