Building iOS 14 Widgets for Carousell - Part 2
Article Summary
Jay Ang and Beemo Lee from Carousell's iOS team shipped their first iOS 14 widget in 2020. Their biggest challenge? Two singleton instances fighting each other across app targets.
When Apple launched iOS 14 widgets, Carousell jumped on the opportunity to bring their Activity tab to users' home screens. The team had to navigate uncharted territory with limited documentation, relying on WWDC videos to answer basic questions about widget capabilities. This deep dive reveals the technical hurdles they hit and the creative solutions they built.
Key Takeaways
- Used DispatchGroup to coordinate multiple API calls for accurate unread counts
- Solved authentication sync by instantiating APIManager per timeline update
- Changed Keychain accessibility to kSecAttrAccessibleAfterFirstUnlock for locked device updates
- Cached latest data to handle network failures gracefully
- Fixed TestFlight nested bundle errors with custom Run Script
Carousell successfully launched their iOS 14 widget by solving cross-target singleton conflicts, authentication syncing, and keychain accessibility issues that most teams will encounter.
About This Article
The widget extension in Carousell couldn't access updated authentication values from the main app. APIManager existed as separate singleton instances across the two targets, so logout events never showed up in the widget.
The team created a fresh APIManager instance inside the getTimeline(in:completion:) method. This way, the widget always pulled the latest authentication credentials from Keychain instead of using an outdated singleton reference.
Authentication stayed in sync between the main app and widget extension in real time. Users no longer saw stale or unauthorized data when their login status changed.