hello.m
#include <stdio.h>
int main(int argc, const char *argv[]) {
printf("hello world!");
return 0;
}
准备 entitlements.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "<http://www.apple.com/DTDs/PropertyList-1.0.dtd>">
<plist version="1.0">
<dict>
<key>application-identifier</key>
<string>tech.macoder.ios-hello</string>
<key>platform-application</key> <true/>
<key>com.apple.private.security.no-container</key> <true/>
</dict>
</plist>
application-identifier
应用bundle id。platform-application
将非Apple二进制文件标记为系统应用。com.apple.private.security.no-container
让应用不在沙盒中运行。如何编译它呢?
## 选择clang xcrun --sdk iphoneos -f clang
## 指定架构 -arch arm64
## 指定sdk -isysroot
## 支持最低版本 -miphoneos-version-min=8.0
`xcrun --sdk iphoneos -f clang` -arch arm64 \\
-isysroot `xcrun --sdk iphoneos --show-sdk-path` \\
-miphoneos-version-min=8.0 \\
-o hello \\
hello.m
## 去符号
`xcrun --sdk iphoneos -f strip` -Sx hello
## 给hello签名&添加权限
`xcrun --sdk iphoneos -f codesign` -f -s "zznQ" --entitlements entitlements.xml hello
main.go
package main
import "fmt"
func main() {
fmt.Println("hello world!")
}
如何编译它呢?那就更简单了:
## 编译
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o go-hello gohello/main.go
## 给go-hello签名&添加权限
`xcrun --sdk iphoneos -f codesign` -f -s "zznQ" --entitlements entitlements.xml go-hello