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 授权
sso sso 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.2'
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

wzxha avatar quange avatar caobug avatar

Stargazers

 avatar Zhihui Xiao avatar Artem avatar hackworld avatar  avatar  avatar BBC6BAE9 avatar  avatar isaced avatar Oliver Ou avatar 一只蟹酱 avatar SoloX avatar  avatar amJunLiang avatar chesongsong avatar  avatar Dong Zhang avatar Chars avatar jjaychen avatar 周辉 avatar jimmy8854 avatar LiuJian avatar  avatar  avatar  avatar Gh.Wang avatar  avatar  avatar  avatar  avatar  avatar

Watchers

isaced avatar Alibaba OSS avatar  avatar  avatar

aliyunpan-ios-sdk's Issues

iOS demo invalid client_secret

PKCE Authorization.
The preconditions and appIDs in the project have been configured according to the Yuque documentation. However, it still says an invalid client_secret error.

Screenshot 2024-01-16 at 17 38 12

Is there a demo that can run stably?

v0.3.1 唤端授权失败

现象:

  • 已安装阿里云盘客户端:跳转阿里云盘客户端后停在如下页面(授权结果:授权码 XXX...),未跳回,未授权成功。 ❌
  • 未安装阿里云盘客户端:通过内置浏览器登录授权正常。✅

调用代码:

try await client.authorize(credentials: .server(AliyunpanBizServerImpl()))

IMG_6196

SDK 版本:0.3.1
阿里云盘客户端版本:5.8.0(37003738)
iOS 系统版本:17.4.1

创建文件夹创建成功,但是代码抛异常

`
func createDirOnDefaultDrive() async{
do {
let driveInfo = try await client.send(AliyunpanScope.User.GetDriveInfo())
let driveId = driveInfo.default_drive_id
let resp = try await client.send(AliyunpanScope.File.CreateFile(.init(drive_id: driveId, parent_file_id: "root", name: self.folderName,type: .folder, check_name_mode: .refuse)))
print(resp)
} catch {
print("error",error)
}
}

`

异常信息

error valueNotFound(Swift.Array, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "part_info_list", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead", underlyingError: nil))

弹出的Web页面怎么才可以有【二维码扫码登录】的选项

我的这个登录页面正常打开了。如图。

只有手机验证码,以及账号密码登录可选。

我想问这个web页面怎么才可以有【二维码扫码登录】的选项

image

我的代码截取如下,按下Button调用authorize

Button("Authorize") {
                    Task {
                        do {
                            let userInfo = try await client.authorize(credentials: .pkce)
                                .send(AliyunpanScope.User.GetUsersInfo())
                            self.userInfo = userInfo
                        } catch {
                            print("Authorize ERR: ", error)
                        }
                    }
                }
                .font(.largeTitle)

文件下载

文件下载的时候必须要传进去一个AliyunpanFile对象
let task = downloader.download(file: file, to: destination)
如果我自己去初始化一个AliyunpanFile对象a,那这个a需要哪些属性有值才行呢,下面所有这些都需要初始化?

public struct AliyunpanFile: Codable {
public let drive_id: String
public let file_id: String
/// 根目录是 root
public let parent_file_id: String
/// 文件名
public let name: String
public let size: Int64?
public let file_extension: String?
/// 文件 hash
public let content_hash: String?
public var category: FileCategory?
public let type: FileType?
/// 缩略图
public let thumbnail: URL?
/// 图片预览图地址、小于 5MB 文件的下载地址。超过5MB 请使用 /getDownloadUrl
public let url: URL?
public let created_at: Date?
public let updated_at: Date?
/// 播放进度
public let play_cursor: String?
/// 图片信息
public let image_media_metadata: MediaMetadata?
/// 视频信息
public let video_media_metadata: MediaMetadata?
/// 视频预览信息
public var video_preview_metadata: AudioMetaData?
}

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.