libiPhone-lib.a去UIWebview

14 篇文章 0 订阅

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 * 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];
    [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
或
lipo -info /Users/xx/Downloads/libiPhone-lib.a

libiPhone-lib.a可能包含arm64,armv7等,可通过这个命令查看,必须查看,记住包含哪些架构

3. 使用URLUtility.mm生成对应架构下URLUtility.o

命令:clang -c +URLUtility.mm路径+ -arch +架构+ -isysroot +xcode路径/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
示例:clang -c /Users/xx/Downloads/URLUtility.mm -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk

这个示例命令用来生成arm64下的URLUtility.o文件。第2步中有哪些架构,这里就使用命令生成那些对应架构下的URLUtility.o文件,执行完命令会在用户文件夹(我的是在这里)生成那个文件。如果要生成其他架构下的,只要把arm64替换就行。
要生成多个文件的话,记得每生成一个文件就剪切到其他地方,防止被替换。
有些文章会在这条命令里写多个架构,及…+ -arch +架构+ -arch +架构+…,这是错误的,如果这么做了,在后续步骤中可能报错,报错语句忘了,其中有个fat单词。
还有一个就是如果出现类似这样的错:xcrun: error: active developer path ("/Users/xx/Downloads/Xcode.app/Contents/Developer") does not exist,执行sudo xcode-select --switch Desktop/Xcode.app/Contents/Developer,switch后面是xcode路径加/Xcode.app/Contents/Developer。

可能会报waring,openURL过时。

记住生成的这些URLUtility.o分别是在什么架构下的。

4. 拆分libiPhone-lib.a各架构文件

命令:lipo +libiPhone-lib.a文件路径+ -thin +架构+ -output +输出路径及输出的文件名
示例:lipo /Users/xx/Downloads/libiPhone-lib.a -thin arm64 -output ./libiPhone-lib64.a
这个命令是拆分为arm64架构下的文件,第2步中有哪些架构,这里就使用命令生成对应架构下的.a文件,命令里只要替换arm64即可。

5. 移除对应架构中原有的URLUtility.o

命令:ar -d +上一步中生成的.a文件路径+ URLUtility.o
示例:ar -d ./libiPhone-lib64.a URLUtility.o

上一步中生成了多少个文件,就要执行这个命令多少次

6. 将新生成的URLUtility.o添加到对应架构的.a文件中

将第3步生成的.o文件添加到第5步对应的.a文件中。
命令:ar -q +上一步生成的.a文件路径+ +第3步中对应架构下的.o文件路径(注意空格)
示例: ar -q ./libiPhone-lib64.a ./URLUtility.o

有多少个.o文件就要执行多少次。

7. 将各架构的.a文件合并生成新的libiPhone-lib.a

命令:lipo -create +.a文件路径+ +.a文件路径+ -output +输出的文件路径/libiPhone-lib.a(注意空格)
示例:lipo -create ./URLUtility64/libiPhone-lib64.a ./URLUtilityv7/libiPhone-libv7.a ./URLUtilityv7s/libiPhone-libv7s.a -output ./new/libiPhone-lib.a
将上一步中所有的.a文件合并生成新的libiPhone-lib.a文件,.a文件之间用空格隔开。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值