-
Notifications
You must be signed in to change notification settings - Fork 12
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
[CHNL-12942] Create a hook to reset badge counts #235
Conversation
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.
Looks good to me, however adding Andrew to the review because he knows way more about the SDKs than I do (so won't approve sorry) - also looks like you need to rerun pre-commit though and have a formatting issue.
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.
Just wondering, why do we need to persist the current badge number to UserDefaults
?
Also, I think we'll want to get have some unit tests for these changes |
this is necessary for how we are going to keep track and increment the badge count, details here but still some things up in the air, might convert to a draft PR in the meantime |
e44002a
to
559fee2
Compare
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.
LGTM, minor comments from Noah and I.
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.
LGTM! Nice work.
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.
Minor nit picks else LGTM.
getBackgroundSetting: { .create(from: UIApplication.shared.backgroundRefreshStatus) | ||
}, | ||
getBadgeAutoClearingSetting: { | ||
Bundle.main.object(forInfoDictionaryKey: "Klaviyo_badge_autoclearing") as? Bool ?? true |
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.
if we are unable to get the plist value we assume that they want to auto clear? I think this is fine but might be good to callout in the readme.
Sources/KlaviyoSwift/Klaviyo.swift
Outdated
/// Sets the badge number on the application icon. Syncs with the persisted count | ||
/// stored in the User Defaults suite set up with the App Group |
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 mention something about how/why this value is used?
[CHNL-12942] Create a hook to reset badge counts
[CHNL-12942] Create a hook to reset badge counts
[CHNL-12942] Create a hook to reset badge counts
Description
These changes introduce a new setter
setBadgeCount
on the SDK. By default this setter will be called on every foreground event to clear it/set the badge count to 0 and controlled by theKlaviyo_badge_autoclearing
flag in the plist, configurable by the developer. The badge count will also be synced with the cached count we track in the App Group User Defaults (to be explained in the updated README instructions). If devs so want to disable the autoclearing and call the setter themselves, they can do so likeKlaviyoSDK().setBadgeCount()
after initialization.Small note: Are we ok with the name setBadgeCount, there is the method on UNUserNotificaitonCenter with the same name.
Check List
Manual Test Plan
Note: this test plan worked fine on device, but did not auto clear on simulator
Default behavior
Klaviyo_badge_autoclearing
to the target app Info.plist as a Boolean and set it to YESbadge = 3
in payload) with the app in the background and observe badge of 3Default behavior turned off
Klaviyo_badge_autoclearing
key is set to NObadge = 3
in payload) with the app in the background and observe badge of 3Custom call with default clearing turned off
KlaviyoSDK().setBadgeCount(0)
to some button or trigger in the appbadge = 3
in payload)Supporting Materials