Skip to content

Commit

Permalink
fix: fix the build error on tvOS (#54)
Browse files Browse the repository at this point in the history
* fix: fix the build error on tvOS

* update: update ci.yml
  • Loading branch information
wzxha authored May 15, 2024
1 parent ac8e293 commit 697af6e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
- name: Test
env:
DESTINATION: platform=${{ matrix.destination }}
run: bundle exec fastlane test
run: bundle exec fastlane test_ci

Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,29 @@ class AliyunpanAuthenticator: NSObject {

func startAuthenticationSession(_ url: URL) async throws -> String {
return try await withCheckedThrowingContinuation { continuation in
let session = ASWebAuthenticationSession(url: url, callbackURLScheme: "smartdrive") { url, error in
if let error {
continuation.resume(with: .failure(error))
return
if #available(iOS 13, macOS 10.15, tvOS 16.0, visionOS 1, *) {
let session = ASWebAuthenticationSession(url: url, callbackURLScheme: "smartdrive") { url, error in
if let error {
continuation.resume(with: .failure(error))
return
}

let components = URLComponents(string: url?.absoluteString ?? "")
if let code = components?.queryItems?.first(where: { $0.name == "code" })?.value {
continuation.resume(with: .success(code))
} else {
continuation.resume(with: .failure(AliyunpanError.AuthorizeError.invalidCode))
}
}
let components = URLComponents(string: url?.absoluteString ?? "")
if let code = components?.queryItems?.first(where: { $0.name == "code" })?.value {
continuation.resume(with: .success(code))
} else {
continuation.resume(with: .failure(AliyunpanError.AuthorizeError.invalidCode))
#if canImport(TVUIKit)
#else
session.presentationContextProvider = self
#endif
DispatchQueue.main.async {
session.start()
}
}
session.presentationContextProvider = self
DispatchQueue.main.async {
session.start()
} else {
continuation.resume(with: .failure(AliyunpanError.AuthorizeError.invalidPlatform))
}
}
}
Expand All @@ -104,9 +111,12 @@ class AliyunpanAuthenticator: NSObject {
}
}

#if canImport(TVUIKit)
#else
extension AliyunpanAuthenticator: ASWebAuthenticationPresentationContextProviding {
@MainActor
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
Platform.mainPresentationAnchor
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/AliyunpanSDK/AliyunpanError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public struct AliyunpanError {
case accessTokenInvalid
/// 授权 code 错误
case invalidCode
/// 当前平台不支持
case invalidPlatform
}

/// 网络层错误
Expand Down
19 changes: 1 addition & 18 deletions Tests/AliyunpanSDKTests/MessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@ import XCTest
@testable import AliyunpanSDK

extension AliyunpanError.AuthorizeError: Equatable {
var stringValue: String {
switch self {
case .invalidAuthorizeURL:
return "invalidAuthorizeURL"
case .notInstalledApp:
return "notInstalledApp"
case .authorizeFailed(let error, let errorMsg):
return "authorizeFailed_\(error ?? "")_\(errorMsg ?? "")"
case .qrCodeAuthorizeTimeout:
return "qrCodeAuthorizeTimeout"
case .accessTokenInvalid:
return "accessTokenInvalid"
case .invalidCode:
return "invalidCode"
}
}

public static func == (lhs: AliyunpanError.AuthorizeError, rhs: AliyunpanError.AuthorizeError) -> Bool {
lhs.stringValue == rhs.stringValue
lhs.localizedDescription == rhs.localizedDescription
}
}

Expand Down
4 changes: 4 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ platform :ios do
test(destination: "platform=tvOS Simulator,name=Apple TV")
end

lane :test_ci do
test(destination: ENV["DESTINATION"])
end

lane :test do |options|
scan(
scheme: "AliyunpanSDK",
Expand Down

0 comments on commit 697af6e

Please sign in to comment.