From a200db0e981cfc2ce104f222676ed4e2748bd9c8 Mon Sep 17 00:00:00 2001 From: Brian Giori Date: Fri, 5 Apr 2024 10:50:34 -0700 Subject: [PATCH] fix: assign deviceId correctly on new device (#492) --- .github/workflows/test.yml | 9 +++++---- Sources/Amplitude/Amplitude.m | 2 +- Tests/AmplitudeTests.m | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f307e57..b111dccd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,10 @@ name: Test -on: [push, pull_request] +on: + pull_request: + push: + branches: + - main jobs: test: @@ -32,9 +36,6 @@ jobs: bundle install pod install - - name: Validate Podfile - run: pod lib lint - - name: iOS Tests run: | xcodebuild test \ diff --git a/Sources/Amplitude/Amplitude.m b/Sources/Amplitude/Amplitude.m index 33352ca6..ddae15d7 100644 --- a/Sources/Amplitude/Amplitude.m +++ b/Sources/Amplitude/Amplitude.m @@ -1686,7 +1686,7 @@ - (void)initializeDeviceInfo { if (self.deviceId == nil) { self.deviceId = [self.dbHelper getValue:DEVICE_ID]; if (![self isValidDeviceId:self.deviceId]) { - self.deviceId = [self _getDeviceId]; + self->_deviceId = [self _getDeviceId]; [self.dbHelper insertOrReplaceKeyValue:DEVICE_ID value:self.deviceId]; } } diff --git a/Tests/AmplitudeTests.m b/Tests/AmplitudeTests.m index 67abcab1..ac06753a 100644 --- a/Tests/AmplitudeTests.m +++ b/Tests/AmplitudeTests.m @@ -1708,9 +1708,9 @@ - (void)testOpenURLFiresDeepLinkEvent { - (void)testGetDeviceIdBeforeInit { NSString *instanceName = @"testGetDeviceIdBeforeAndAfterInit"; - // Clear device ID from db + // Delete DB before running the test to start fresh AMPDatabaseHelper *dbHelper = [AMPDatabaseHelper getDatabaseHelper:instanceName]; - [dbHelper insertOrReplaceKeyValue:@"device_id" value:nil]; + [dbHelper deleteDB]; // Device ID should get generated before api key init Amplitude *client = [Amplitude instanceWithName:instanceName];