Unity iOS 删除 UIWebView

Unity iOS 删除 UIWebView

https://www.colabug.com/2020/0113/6839873/amp/

 

 

 

CoLaBug.com Exit Reader Mode

Unity iOS 删除 UIWebView

狂飙

4月 ago

介绍

 

苹果在审核拒约时给出了以下信息:

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 构建一个空工程上传到 QuickSDK
进行预先检查,发现依然存在 UIWebView API 调用。

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

环境

  • Unity 5.6.6f2
  • macOS 10.14.6
  • Xcode 11.0

解决方案

虽然 Unity 官方不准备在旧版本修复此 Bug,但是在问题描述中阐述了具体细节:在 PlatformDependent/iPhonePlayer/URLUtility.mm
中使用 UIWebView 处理游戏内链接。

搜索后找到了一个现成的解决方案,经过测试后可用:

下面记录一下实践过程并补充一些相关信息。

保存源文件

首先将以下内容保存为 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];
}

编译

原文只使用了 arm64 架构,实际上通过 file 命令查看 libiPhone-lib.a
是三个架构:

$ file libiPhone-lib.a
libiPhone-lib.a: Mach-O universal binary with 3 architectures: [arm_v7:current ar archive] [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

因此在编译时建议三种架构都编译,否则在替换时会提示缺失符号问题。

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

执行完当前目录会生成 URLUtility.o
目标文件。

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

替换

首先要明确, libiPhone-lib.a
是一个存档文件,内部保存了许多目标文件,可以使用 ar -tv libiPhone-lib.a
显示内容。

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

ar
命令的具体使用方法可以通过执行 man ar
查看。

建议

可以将以上步骤放到构建流程里,每次出包的时候自动将 Xcode 工程内的 libiPhone-lib.a
替换。

Categories: 综合开发

Tags: UIWebView, Unity

CoLaBug.com

Back to top

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值