Skip to content

Commit

Permalink
feat: modify the authorization and the command, support visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxha committed Mar 1, 2024
1 parent ccfecb4 commit ff0335d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
8 changes: 6 additions & 2 deletions AliyunpanSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@
F4C6F23E2B060C4B003A06B3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
Expand All @@ -882,7 +883,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
SUPPORTED_PLATFORMS = "xrsimulator xros watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos";
SUPPORTS_MACCATALYST = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand All @@ -894,6 +896,7 @@
F4C6F23F2B060C4B003A06B3 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
Expand All @@ -911,7 +914,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
SUPPORTED_PLATFORMS = "xrsimulator xros watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos";
SUPPORTS_MACCATALYST = YES;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
Expand Down
49 changes: 31 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
## 快速开始

### 1. 创建 Client
```swift
let client: AliyunpanClient = AliyunpanClient(
.init(
appId: "YOUR_APP_ID",
scope: "YOUR_SCOPE", // e.g. user:base,file:all:read
)
)
```

你可以使用 SDK 提供的任意授权方式创建 Client
### 2. 授权
你可以使用 SDK 提供的多种授权方式授权
#### [Credentials](https://alibaba.github.io/aliyunpan-ios-sdk/Enums/AliyunpanCredentials.html)

| 授权方式 | 描述 | **不需要** Server | **不需要**阿里云盘客户端 |
Expand All @@ -38,31 +47,32 @@
| token | 注入 token 授权 |||

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

### 2. 发送命令
### 3. 发送命令

使用 SDK,你可以轻松使用所有已提供的 OpenAPI 和它们的请求体、返回体模型

```swift
// 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
try await client
.authorize() // 默认 pkce
.send(AliyunpanScope.User.GetUsersInfo()) // -> GetUsersInfo.Response

try await client
.authorize()
.send(
AliyunpanScope.File.GetFileList(
.init(drive_id: driveId, parent_file_id: "root")))) // -> GetFileList.Response

// Closure
client.send(
AliyunpanScope.User.GetUsersInfo()) { result in
/// do something
}
client
.authorize()
.send(
AliyunpanScope.User.GetUsersInfo()) { result in
/// do something
}
```

## 高级功能
Expand Down Expand Up @@ -120,6 +130,9 @@ end

[👉 文档](https://alibaba.github.io/aliyunpan-ios-sdk/)

## TODO
- Alamofire、URLSession 拓展

## License

This project is licensed under the [MIT License](LICENSE).
6 changes: 3 additions & 3 deletions Tests/AliyunpanSDKTests/AliyunpanClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import XCTest

class AliyunpanClientTests: XCTestCase {
@MainActor func testToken() {
let client1 = AliyunpanClient(.init(appId: "app", scope: "scope", identifier: "user1", credentials: .pkce))
let client2 = AliyunpanClient(.init(appId: "app", scope: "scope", identifier: "user2", credentials: .pkce))
let client3 = AliyunpanClient(.init(appId: "app", scope: "scope", credentials: .pkce))
let client1 = AliyunpanClient(.init(appId: "app", scope: "scope", identifier: "user1"))
let client2 = AliyunpanClient(.init(appId: "app", scope: "scope", identifier: "user2"))
let client3 = AliyunpanClient(appId: "app", scope: "scope")

let now = Date()
let token = AliyunpanToken(
Expand Down

0 comments on commit ff0335d

Please sign in to comment.