iOS开发工具集合,包含以下模块:
- OpenAI API 调用
- 飞书机器人
- 飞书自定义机器人
- 阿里云OSS
- 工具类
- iOS 16.0+
- macOS 13.0+
- Swift 5.9+
在你的 Package.swift
文件中添加依赖:
dependencies: [
.package(url: "你的仓库地址", branch: "main")
]
或者在 Xcode 中:
- File > Add Packages
- 输入仓库地址
- 选择 "main" 分支
git clone 你的仓库地址
cd ios_tools
在 Sources/ios_tools/OpenAI/Demo/main.swift
中设置你的 API Key:
let openAI = OpenAI(apiKey: "your-api-key")
在 Sources/ios_tools/LarkBot/Demo/main.swift
中设置你的 App ID 和 App Secret:
let larkBot = LarkBot(appId: "your-app-id", appSecret: "your-app-secret")
在 Sources/ios_tools/LarkCustomBot/Demo/main.swift
中设置 Webhook URL:
let customBot = LarkCustomBot(webhookURL: "your-webhook-url")
在 Sources/ios_tools/AliyunOSS/Demo/main.swift
中设置相关配置:
let oss = AliyunOSS(
endpoint: "your-endpoint",
accessKeyId: "your-access-key-id",
accessKeySecret: "your-access-key-secret",
bucketName: "your-bucket-name"
)
每个模块都有对应的Demo可以运行测试:
swift run OpenAIDemo
swift run LarkBotDemo
swift run LarkCustomBotDemo
swift run AliyunOSSDemo
import ios_tools_lib
let openAI = OpenAI(apiKey: "your-api-key")
let response = try await openAI.chat(messages: [
.init(role: .user, content: "Hello!")
])
print(response)
import ios_tools_lib
let larkBot = LarkBot(appId: "your-app-id", appSecret: "your-app-secret")
try await larkBot.sendMessage(
chatId: "your-chat-id",
msg: "Hello from LarkBot!"
)
import ios_tools_lib
let customBot = LarkCustomBot(webhookURL: "your-webhook-url")
try await customBot.sendMessage("Hello from CustomBot!")
import ios_tools_lib
let oss = AliyunOSS(
endpoint: "your-endpoint",
accessKeyId: "your-access-key-id",
accessKeySecret: "your-access-key-secret",
bucketName: "your-bucket-name"
)
// 上传文件
try await oss.upload(
fileData: data,
toPath: "path/in/bucket/file.txt"
)
// 下载文件
let downloadedData = try await oss.download(
fromPath: "path/in/bucket/file.txt"
)
- 请确保所有的密钥和敏感信息都保存在安全的地方,不要直接提交到代码仓库
- 在生产环境中使用时,建议使用环境变量或配置文件来管理密钥
- 每个模块的Demo文件夹中都有更详细的使用示例
MIT-License