Skip to content

Commit

Permalink
feat: add method to get device ID synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Apr 3, 2024
1 parent 56446ae commit cf0151d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ - (NSString *)getDeviceId {
return self.deviceId;
}

- (NSString *)getDeviceIdSync {
return [self initializeDeviceId];
}

- (long long)getSessionId {
return _sessionId;
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/Amplitude/Public/Amplitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ typedef void (^AMPInitCompletionBlock)(void);
*/
- (NSString *)getDeviceId;

/**
Fetches the deviceId synchronously. This must be called after initialization, but will access the device ID from the storage or generate one if the asynchronous intialization function has not reached that point yet. The device ID is a unique identifier shared between multiple users using the same app on the same device.
@returns the deviceId.
*/
- (NSString *)getDeviceIdSync;

/**
Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you are doing. This can be used in conjunction with setUserId:nil to anonymize users after they log out. With a nil userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
Expand Down

0 comments on commit cf0151d

Please sign in to comment.