Skip to content

persistent deviceId #910

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kuhash
Copy link

@Kuhash Kuhash commented Apr 2, 2025

✏️ Description

Constant value across the app update and reinstall process.

@Ayyanchira Ayyanchira requested a review from Copilot April 2, 2025 22:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements a persistent deviceId that remains constant across app updates and reinstalls. Key changes include updates to test cases (using Self instead of class name), a non-optional deviceId in LocalStorage and its protocol, and modifications to keychain and constants to support persistent deviceId management.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/unit-tests/LocalStorageTests.swift Refactored to use Self and updated tests for deviceId and keychain behavior
tests/common/MockLocalStorage.swift Changed deviceId from an optional to a fixed non-optional string for consistent testing
swift-sdk/Internal/Utilities/LocalStorageProtocol.swift Updated deviceId to a non-optional String with a getter only
swift-sdk/Internal/Utilities/LocalStorage.swift Revised deviceId getter to incorporate persistent retrieval logic with state updates
swift-sdk/Internal/Utilities/Keychain/IterableKeychain.swift No functional changes; maintains deviceId storage in the keychain
swift-sdk/Internal/InternalIterableAPI.swift Simplified deviceId logic reflecting the new persistent approach
swift-sdk/Core/Constants.swift Added a constant entry for deviceId

Comment on lines +49 to +62
let foundDeviceId = [
iterableUserDefaults.deviceId,
keychain.deviceId,
UIDevice.current.identifierForVendor?.uuidString
].compactMap { $0 }.first
let deviceId = foundDeviceId ?? IterableUtil.generateUUID()

if iterableUserDefaults.deviceId == nil {
iterableUserDefaults.deviceId = deviceId
}
if keychain.deviceId == nil {
keychain.deviceId = deviceId
}
return deviceId
Copy link
Preview

Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getter for 'deviceId' modifies state by writing to user defaults and keychain, which may lead to unexpected side effects. Consider refactoring this logic so that state mutations occur in an explicit initialization or setter method rather than within a property getter.

Suggested change
let foundDeviceId = [
iterableUserDefaults.deviceId,
keychain.deviceId,
UIDevice.current.identifierForVendor?.uuidString
].compactMap { $0 }.first
let deviceId = foundDeviceId ?? IterableUtil.generateUUID()
if iterableUserDefaults.deviceId == nil {
iterableUserDefaults.deviceId = deviceId
}
if keychain.deviceId == nil {
keychain.deviceId = deviceId
}
return deviceId
return iterableUserDefaults.deviceId ?? keychain.deviceId ?? UIDevice.current.identifierForVendor?.uuidString ?? ""

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, provided code's logic is correct, we want to filter out first non nil from array of values, but if it fails generateUUID will be called, also you deleted persistency to UserDefaults and/or Keychain

@Kuhash
Copy link
Author

Kuhash commented Apr 3, 2025

Are those building errors related to 404 https://www.travis-ci.com/Iterable/swift-sdk ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant