c&objc

#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>

如何编译它呢?

## 选择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

golang

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