在开始前,请查看阿里云盘开放平台接入指南:
let client: AliyunpanClient = AliyunpanClient(
.init(
appId: "YOUR_APP_ID",
scope: "YOUR_SCOPE", // e.g. user:base,file:all:read
)
)
你可以使用 SDK 提供的多种授权方式授权
授权方式 | 描述 | 不需要 Server | 不需要阿里云盘客户端 |
---|---|---|---|
pkce | pkce 授权 | ✅ | ✅ |
sso | sso pkce 授权 | ✅ | ✅ |
server | 业务后端授权 | ❌ | ✅ |
qrCode | 二维码授权 | ✅ | ✅ |
token | 注入 token 授权 | ✅ | ✅ |
client.authorize(credentials: credentials)
使用 SDK,你可以轻松使用所有已提供的 OpenAPI 和它们的请求体、返回体模型
// Concurrency
try await client.send(
AliyunpanScope.User.GetUsersInfo()) // -> GetUsersInfo.Response
try await client.send(
AliyunpanScope.File.GetFileList(
.init(drive_id: driveId, parent_file_id: "root")))) // -> GetFileList.Response
// Closure
client.send(
AliyunpanScope.User.GetUsersInfo()) { result in
/// do something
}
let uploader = client.uploader
// 上传
let task = Task {
let file = try? await uploader.upload(
fileURL: url,
fileName: fileName,
driveId: driveId,
folderId: folderId,
useProof: true // 是否开启快传
)
}
// 取消
task.cancel()
let downloader = client.downloader
// 下载
let task = downloader.download(file: file, to: destination)
// let task = downloader.tasks.first
// 修改并发数,默认为10
downloader.maxConcurrentOperationCount = 10
// 暂停
downloader.pause(task)
// 恢复
downloader.resume(task)
// 取消
downloader.cancel(task)
// AliyunpanDownloadDelegate
// 下载速度变化
// func downloader(_ downloader: AliyunpanDownloader, didUpdatedNetworkSpeed networkSpeed: Int64)
// 下载任务状态变化
// func downloader(_ downloader: AliyunpanDownloader, didUpdateTaskState state: AliyunpanDownloadTask.State, for task: AliyunpanDownloadTask)
downloadr.addDelegate(DELEGATE)
- File > Swift Packages > Add Package Dependency
- 添加
https://github.com/alibaba/aliyunpan-ios-sdk.git
target 'MyApp' do
pod 'AliyunpanSDK', '~> 0.2'
end
- iOS 13.0+ (CocoaPods)
- Swift 5.0+
- Alamofire、URLSession 拓展
This project is licensed under the MIT License.