Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SDK does not properly wait for initialization #168

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
* _Contributing to this repo? Add info about your change here to be included in the next release_


### 5.9.3
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.2...5.9.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.9.3/documentation/parseswift)

__Fixes__
* Certain calls to the user or installation did not wait for the SDK to initialize causing a crash ([#163](https://github.com/netreconlab/Parse-Swift/pull/163)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.9.2
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.1...5.9.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.9.2/documentation/parseswift)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public extension ParseUser {
}

internal func linkCommand(body: SignupLoginBody) async throws -> API.Command<SignupLoginBody, Self> {
try await yieldIfNotInitialized()
let currentStrippedUser = try await self.anonymous.strip()
var body = body
if var currentAuthData = currentStrippedUser.authData {
Expand Down
21 changes: 18 additions & 3 deletions Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1230,10 +1230,25 @@
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
desires a different policy, it should be inserted in `options`.
*/
static func deleteObjCKeychain(options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<Void, ParseError>) -> Void) {
static func deleteObjCKeychain( // swiftlint:disable:this function_body_length
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<Void, ParseError>) -> Void
) {
Task {
do {
try await yieldIfNotInitialized()
} catch {
let defaultError = ParseError(
code: .otherCause,
swift: error
)
let parseError = error as? ParseError ?? defaultError
callbackQueue.async {
completion(.failure(parseError))
}
return

Check warning on line 1250 in Sources/ParseSwift/Objects/ParseInstallation.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ParseSwift/Objects/ParseInstallation.swift#L1242-L1250

Added lines #L1242 - L1250 were not covered by tests
}
guard let objcParseKeychain = KeychainStore.objectiveC,
// swiftlint:disable:next line_length
let oldInstallationId: String = await objcParseKeychain.objectObjectiveC(forKey: "installationId") else {
Expand Down
14 changes: 14 additions & 0 deletions Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
}

internal static func setCurrent(_ newValue: Self?) async throws {
try await yieldIfNotInitialized()
var currentContainer = await Self.currentContainer()
if let newValue = newValue,
let currentUser = currentContainer?.currentUser {
Expand Down Expand Up @@ -438,6 +439,19 @@
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<Self, ParseError>) -> Void) {
Task {
do {
try await yieldIfNotInitialized()
} catch {
let defaultError = ParseError(
code: .otherCause,
swift: error
)
let parseError = error as? ParseError ?? defaultError
callbackQueue.async {
completion(.failure(parseError))
}
return

Check warning on line 453 in Sources/ParseSwift/Objects/ParseUser.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ParseSwift/Objects/ParseUser.swift#L445-L453

Added lines #L445 - L453 were not covered by tests
}
let objcParseKeychain = KeychainStore.objectiveC
// swiftlint:disable:next line_length
guard let objcParseUser: [String: String] = await objcParseKeychain?.objectObjectiveC(forKey: "currentUser"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "5.9.2"
static let version = "5.9.3"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
Loading