Skip to content

Commit

Permalink
feat: modify the authorization and the command, support visionOS (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxha authored Mar 1, 2024
1 parent 780c130 commit b2d0c77
Show file tree
Hide file tree
Showing 31 changed files with 659 additions and 163 deletions.
1 change: 1 addition & 0 deletions AliyunpanSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Pod::Spec.new do |spec|
spec.ios.deployment_target = "13.0"
spec.tvos.deployment_target = "13.0"
spec.osx.deployment_target = "10.15"
spec.visionos.deployment_target = "1.0"

spec.source = { :git => "https://github.com/alibaba/aliyunpan-ios-sdk.git", :tag => "v#{spec.version}" }

Expand Down
18 changes: 12 additions & 6 deletions AliyunpanSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
XROS_DEPLOYMENT_TARGET = 1.0;
};
name = Debug;
};
Expand Down Expand Up @@ -762,6 +763,7 @@
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
XROS_DEPLOYMENT_TARGET = 1.0;
};
name = Release;
};
Expand Down Expand Up @@ -803,12 +805,12 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = "";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3";
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Debug;
};
Expand Down Expand Up @@ -851,18 +853,19 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = "";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3";
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Release;
};
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 @@ -880,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 @@ -892,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 @@ -909,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
237 changes: 236 additions & 1 deletion Demo/Demo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Demo/Demo/Client.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Client.swift
// Demo
//
// Created by zhaixian on 2024/2/20.
//

import Foundation
import AliyunpanSDK

let appId = "YOUR_APP_ID" // 替换成你的 AppID
let scope = "user:base,file:all:read,file:all:write"

let client = AliyunpanClient(
appId: appId,
scope: scope
)
4 changes: 1 addition & 3 deletions Demo/Demo/Demo-MacOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import Cocoa
import AliyunpanSDK

@main
class AppDelegate: NSObject, NSApplicationDelegate {
var client: AliyunpanClient?

class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
Aliyunpan.setLogLevel(.info)
}
Expand Down
29 changes: 9 additions & 20 deletions Demo/Demo/Demo-MacOS/ExamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi

let examples = Example.allCases

var client: AliyunpanClient? {
(NSApplication.shared.delegate as! AppDelegate).client
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -39,9 +35,6 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
}

func tableViewSelectionDidChange(_ notification: Notification) {
guard let client else {
return
}
// 当选中的行发生变化时被调用
let selectedRow = tableView.selectedRow

Expand All @@ -54,7 +47,7 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .getUserInfo:
Task {
do {
let vipInfo = try await client.send(AliyunpanScope.User.GetUsersInfo())
let vipInfo = try await client.authorize().send(AliyunpanScope.User.GetUsersInfo())
showAlert(message: String(describing: vipInfo))
} catch {
showAlert(message: String(describing: error))
Expand All @@ -63,7 +56,7 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .getDriveInfo:
Task {
do {
let vipInfo = try await client.send(AliyunpanScope.User.GetDriveInfo())
let vipInfo = try await client.authorize().send(AliyunpanScope.User.GetDriveInfo())
showAlert(message: String(describing: vipInfo))
} catch {
showAlert(message: String(describing: error))
Expand All @@ -72,7 +65,7 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .getSpaceInfo:
Task {
do {
let vipInfo = try await client.send(AliyunpanScope.User.GetSpaceInfo())
let vipInfo = try await client.authorize().send(AliyunpanScope.User.GetSpaceInfo())
showAlert(message: String(describing: vipInfo))
} catch {
showAlert(message: String(describing: error))
Expand All @@ -81,7 +74,7 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .getVIPInfo:
Task {
do {
let vipInfo = try await client.send(AliyunpanScope.User.GetVipInfo())
let vipInfo = try await client.authorize().send(AliyunpanScope.User.GetVipInfo())
showAlert(message: String(describing: vipInfo))
} catch {
showAlert(message: String(describing: error))
Expand All @@ -90,19 +83,19 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .getVipFeatureList:
Task {
do {
let featureList = try await client.send(AliyunpanScope.VIP.GetVipFeatureList())
let featureList = try await client.authorize().send(AliyunpanScope.VIP.GetVipFeatureList())
showAlert(message: String(describing: featureList))
} catch {
showAlert(message: String(describing: error))
}
}
case .fetchFileList:
Task {
let driveInfo = try await client.send(AliyunpanScope.User.GetDriveInfo())
let driveInfo = try await client.authorize().send(AliyunpanScope.User.GetDriveInfo())

let driveId = driveInfo.default_drive_id

let fileList = try await client.send(AliyunpanScope.File.GetFileList(.init(drive_id: driveId, parent_file_id: "root"))).items
let fileList = try await client.authorize().send(AliyunpanScope.File.GetFileList(.init(drive_id: driveId, parent_file_id: "root"))).items

showFileDetailViewController(files: fileList)
}
Expand All @@ -111,11 +104,11 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
case .createFolderOnRoot:
Task {
do {
let driveInfo = try await client.send(AliyunpanScope.User.GetDriveInfo())
let driveInfo = try await client.authorize().send(AliyunpanScope.User.GetDriveInfo())

let driveId = driveInfo.default_drive_id

let response = try await client.send(
let response = try await client.authorize().send(
AliyunpanScope.File.CreateFile(
.init(
drive_id: driveId,
Expand Down Expand Up @@ -158,10 +151,6 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
}

class DetailViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
var client: AliyunpanClient? {
(NSApplication.shared.delegate as! AppDelegate).client
}

var files: [AliyunpanFile] = []

var parentDetailViewController: DetailViewController?
Expand Down
17 changes: 3 additions & 14 deletions Demo/Demo/Demo-MacOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,12 @@
import Cocoa
import AliyunpanSDK

class ViewController: NSViewController {
private lazy var client: AliyunpanClient = {
let client = AliyunpanClient(
.init(
appId: "YOUR_APP_ID", // 替换成你的 AppID
scope: "user:base,file:all:read,file:all:write",
credentials: .qrCode(self)))
return client
}()

class ViewController: NSViewController {
private var authorizeButton = NSButton()
private var imageView = NSImageView()

override func viewDidLoad() {
super.viewDidLoad()

(NSApplication.shared.delegate as! AppDelegate).client = client

authorizeButton.title = "Authorize"
authorizeButton.bezelStyle = .roundRect
view.addSubview(authorizeButton)
Expand Down Expand Up @@ -60,7 +48,8 @@ class ViewController: NSViewController {
@objc private func showQRCode() {
Task {
do {
try await client.authorize()
try await client.authorize(
credentials: .qrCode(self))
} catch {
print(error)
}
Expand Down
6 changes: 0 additions & 6 deletions Demo/Demo/Demo-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import AliyunpanSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
let client = AliyunpanClient(
.init(
appId: "YOUR_APP_ID", // 替换成你的 AppID
scope: "user:base,file:all:read,file:all:write",
credentials: .pkce))

func applicationDidFinishLaunching(_ application: UIApplication) {
Aliyunpan.setLogLevel(.info)
}
Expand Down
38 changes: 20 additions & 18 deletions Demo/Demo/Demo-iOS/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ class FileListViewController: UIViewController {
label.font = UIFont.monospacedSystemFont(ofSize: 12, weight: .regular)
return label
}()

private lazy var client: AliyunpanClient = {
let client = (UIApplication.shared.delegate as! AppDelegate).client
client.downloader.addDelegate(self)
client.downloader.enableNetworkSpeedMonitor()
return client
}()

private lazy var dataSource: UICollectionViewDiffableDataSource<Int, DisplayItem> = {
let cellRegistration = UICollectionView.CellRegistration<FileCell, DisplayItem> { [weak self] cell, _, item in
Expand Down Expand Up @@ -75,6 +68,9 @@ class FileListViewController: UIViewController {
snapshot.appendSections([0])
snapshot.appendItems(displayItems)
dataSource.apply(snapshot)

client.downloader.addDelegate(self)
client.downloader.enableNetworkSpeedMonitor()
}

/// 播放音频
Expand All @@ -99,7 +95,9 @@ class FileListViewController: UIViewController {
@MainActor
private func navigateToFolder(_ folder: AliyunpanFile) {
Task {
let files = try await client.send(AliyunpanScope.File.GetFileList(
let files = try await client
.authorize()
.send(AliyunpanScope.File.GetFileList(
.init(drive_id: folder.drive_id, parent_file_id: folder.file_id)))
.items

Expand All @@ -126,11 +124,13 @@ extension FileListViewController: UICollectionViewDelegate {
case .video:
Task {
do {
let playInfo = try await self.client.send(
AliyunpanScope.Video.GetVideoPreviewPlayInfo(
.init(
drive_id: file.drive_id,
file_id: file.file_id)))
let playInfo = try await client
.authorize()
.send(
AliyunpanScope.Video.GetVideoPreviewPlayInfo(
.init(
drive_id: file.drive_id,
file_id: file.file_id)))

/// 获取画质最高的已转码播放链接
let playURL = playInfo.video_preview_play_info.live_transcoding_task_list
Expand All @@ -149,11 +149,13 @@ extension FileListViewController: UICollectionViewDelegate {
Task {
do {
/// 目前音频需要使用 download url 播放
let playURL = try await self.client.send(
AliyunpanScope.File.GetFileDownloadUrl(
.init(
drive_id: file.drive_id,
file_id: file.file_id))).url
let playURL = try await client
.authorize()
.send(
AliyunpanScope.File.GetFileDownloadUrl(
.init(
drive_id: file.drive_id,
file_id: file.file_id))).url
playMedia(playURL)
} catch {
print(error)
Expand Down
Loading

0 comments on commit b2d0c77

Please sign in to comment.