起因
最近在打包上传 iOS 项目时发现了下面的报错提醒, UIWebView 被弃用了
解决方案
首先用下面的指令在 Xcode 项目中查看那个模块使用了 UIWebView
,如果是 libiPhone-lib.a
文件,就继续往下看,如果不是,就需要考虑将引用的模块移除
grep UIWebView * -R
仓库中的 README 怎么使用写的很详细,这里不再做赘述
剩下的就是把新的 .a
文件每次打包时,自动放入工程中替换
我自己项目中写了一套 Build 流程,当完成打包后,会调用
BuildiOS.sh
去执行自动导出ipa
的功能,只需要额外添加一段cp
指令即可
#!/bin/bash
echo -----------------------------------------------------
echo ----------------- Copy .a file ----------------------
echo -----------------------------------------------------
cp -f libiPhone-lib.a ../../../Builds/xxx/Libraries/libiPhone-lib.a
Unity 项目中加入如下代码
private static void OnIOSBuild(WeChatGroup wechatGrop) {
Log.Debug("iOS 工程打包成功,正在导出iPA并上传");
ProcessHelper.Run(
"/bin/sh",
"BuildiOS.sh",
"./Tools/AutoBuild/",
true
);
Log.Debug("iOS iPA 已成功上传");
WeChatHelper.Notify($"iOS App 已发布,下载地址: https://xxxx.com", wechatGrop);
}
在 Mac 和 Windows 环境下都可以使用下面的工具类调用命令行执行命令
public static class ProcessHelper {
public static Process Run(string exe,
string arguments,
string workingDirectory = ".",
bool waitExit = false) {
try{
bool redirectStandardOutput = true;
bool redirectStandardError = true;
bool useShellExecute = false;
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){
redirectStandardOutput = false;
redirectStandardError = false;
useShellExecute = true;
}
if(waitExit){
redirectStandardOutput = true;
redirectStandardError = true;
useShellExecute = false;
}
ProcessStartInfo info = new ProcessStartInfo {
FileName = exe,
Arguments = arguments,
CreateNoWindow = true,
UseShellExecute = useShellExecute,
WorkingDirectory = workingDirectory,
RedirectStandardOutput = redirectStandardOutput,
RedirectStandardError = redirectStandardError,
};
Process process = Process.Start(info);
if(waitExit){
process.WaitForExit();
if(process.ExitCode != 0){
throw new Exception(
$"{process.StandardOutput.ReadToEnd()} {process.StandardError.ReadToEnd()}"
);
}
}
return process;
}
catch(Exception e){
throw new Exception($"dir: {Path.GetFullPath(workingDirectory)}, command: {exe} {arguments}", e);
}
}
}
微信通知
我自己的微信通知使用的是上面的微信版本,需要开启 Alfred
功能才可以自动发送微信通知
在 Alfred
中 sendMsg.py
是发送信息的核心逻辑,我们需要保存待通知的 userId
、srvId
和 baseUrl
中间保存的逻辑是我自己添上去的,这样会把这些关键信息存在
output.txt
文件中
然后使用 Alfred
找到需要通知的对象,随便发送一条测试信息,在 output.txt
文件中可以找到对应的关键信息
剩下的就很简单了, 使用
ProcessHelper
工具,调用curl
发送微信消息即可,
public static class WeChatHelper {
private static string _code =
"-d \"userId={0}&content={1}&srvId=0\" http://127.0.0.1:52700/wechat-plugin/send-message";
private static string _groupID = "xxx@chatroom";
public static void Notify(string content) {
string arguments = string.Empty;
arguments = string.Format(_code, _groupID, content);
ProcessHelper.Run(
"/usr/bin/curl",
arguments,
".",
true
);
}
}
Comments | NOTHING