Skip to content

Commit

Permalink
Make sure the channel ID stays the same between versions (#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
oristanovic authored Mar 23, 2023
1 parent d6e068f commit 2ab8a30
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions Airship/AirshipCore/Source/AirshipKeychainAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ public class AirshipKeychainAccess: NSObject {
identifier: identifier,
service: self.service
)

// Delete old
// Write to old location in case of a downgrade
if let bundleID = Bundle.main.bundleIdentifier {
Keychain.deleteCredentials(
let _ = Keychain.writeCredentials(
credentials,
identifier: identifier,
service: bundleID
)
}

completionHandler?(result)
}
}
Expand Down Expand Up @@ -135,39 +136,35 @@ public class AirshipKeychainAccess: NSObject {

/// Helper method that migrates data from the old storage location to the new on read.
private func readCredentialsHelper(identifier: String) -> AirshipKeychainCredentials? {
var credentials = Keychain.readCredentials(
if let credentials = Keychain.readCredentials(
identifier: identifier,
service: self.service
)

) {
return credentials
}

// If we do not have a new value, check
// the old service location
if credentials == nil, let bundleID = Bundle.main.bundleIdentifier {

credentials = Keychain.readCredentials(
if let bundleID = Bundle.main.bundleIdentifier {
let old = Keychain.readCredentials(
identifier: identifier,
service: bundleID
)

if let credentials = credentials {
if let old = old {
// Migrate old data to new service location
let result = Keychain.writeCredentials(
credentials,
let _ = Keychain.writeCredentials(
old,
identifier: identifier,
service: self.service
)
if (result) {
Keychain.deleteCredentials(
identifier: identifier,
service: bundleID
)
} else {
AirshipLogger.error("Failed to migrate credentials")
}

return old
}
}

return credentials
return nil
}
}

Expand Down

0 comments on commit 2ab8a30

Please sign in to comment.