Skip to content

Commit

Permalink
fix: assign deviceId correctly on new device (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori authored Apr 5, 2024
1 parent 7960a7e commit a200db0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Test

on: [push, pull_request]
on:
pull_request:
push:
branches:
- main

jobs:
test:
Expand Down Expand Up @@ -32,9 +36,6 @@ jobs:
bundle install
pod install
- name: Validate Podfile
run: pod lib lint

- name: iOS Tests
run: |
xcodebuild test \
Expand Down
2 changes: 1 addition & 1 deletion Sources/Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/AmplitudeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit a200db0

Please sign in to comment.