-
Notifications
You must be signed in to change notification settings - Fork 292
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
[PoC] cloud synced anonymous ids #3806
base: main
Are you sure you want to change the base?
Conversation
private let store = NSUbiquitousKeyValueStore.default | ||
private enum Constants { | ||
static let keyValueStoreKey: String = "appUserID" | ||
static let appUserIDPrefix: String = "$RCCloudAnonymousID:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
different prefix, so that we can still easily detect it, but the backend doesn't treat it as a regular anonymous user id (otherwise we'd be back to square one)
if let reason = userInfo[NSUbiquitousKeyValueStoreChangeReasonKey] as? NSNumber { | ||
if reason.intValue == NSUbiquitousKeyValueStoreAccountChange { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the trickiest part, since this notification could be triggered by either another device logging in / out, or you switching store accounts.
Not entirely sure how to solve it, I suppose one way would be to somewhat mix this in with a value that's unique per device... that is, if we do want to solve it.
It's kinda cool in that it allows you to have the user logged in on multiple devices at once, which if you're not using an accounts system, would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, I tested this across two devices, and it's pretty neat that when you log out on one it logs out the other and they both change to the same appUserID
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(self.ubiquitousKeyValueStoreDidChange), | ||
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we only subscribe to this if in cloudSyncedAnonymousIDMode
? Maybel also the applicationWillEnterForegroundNotification
subscribe since right now it's only for this use case as well
logOut() called with cloud synced appUserIDs enabled. The current user will be logged out, and | ||
a new appUserID will be generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the same that happens in a normal logout right? Maybe we should mention that the iCloud user id has been reset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, probably a copy/pasted string that I meant to update
This allows an app that doesn't have an account system to automatically sync anonymous IDs.
This is helpful in a few ways:
This is achieved by using
NSUbiquituousKeyValueStorage
, which syncs data through iCloud. Each app only gets 1mb worth of data, but we're only storing a single string.Missing: