Skip to content

Commit

Permalink
fix: SDK does not properly wait for initialization (#168)
Browse files Browse the repository at this point in the history
* fix: SDK does not properly wait for initialization

* add a change log entry

* lint
  • Loading branch information
cbaker6 committed Apr 1, 2024
1 parent 702ca34 commit 9b7a960
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
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 @@ public extension ParseInstallation {
- 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
}
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 @@ public extension ParseUser {
}

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 @@ extension ParseUser {
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
}
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

0 comments on commit 9b7a960

Please sign in to comment.