Giter VIP home page Giter VIP logo

aliyunpan-ios-sdk's Introduction

AliyunpanSDK

This is the open-source SDK for Aliyunpan OpenAPI.

示例 · 反馈 Bug · 提交需求

准备工作

在开始前,请查看阿里云盘开放平台接入指南:

👉 如何注册三方开发者

快速开始

1. 创建 Client

let client: AliyunpanClient = AliyunpanClient(
    .init(
        appId: "YOUR_APP_ID",
        scope: "YOUR_SCOPE", // e.g. user:base,file:all:read
    )
)

2. 授权

你可以使用 SDK 提供的多种授权方式授权

授权方式 描述 不需要 Server 不需要阿里云盘客户端
pkce pkce 授权
server 业务后端授权
qrCode 二维码授权
token 注入 token 授权
client.authorize(credentials: credentials)

3. 发送命令

使用 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)

示例

FileListViewController

安装方式

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • 添加 https://github.com/alibaba/aliyunpan-ios-sdk.git

CocoaPods

target 'MyApp' do
  pod 'AliyunpanSDK', '~> 0.1'
end

要求

  • iOS 13.0+ (CocoaPods)
  • Swift 5.0+

文档

👉 文档

TODO

  • Alamofire、URLSession 拓展

License

This project is licensed under the MIT License.

aliyunpan-ios-sdk's People

Contributors

quange avatar wzxha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.