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
Feature/defer cache updates if woken from push notification #288
Feature/defer cache updates if woken from push notification #288
Conversation
…ier. Added tests to check that caches aren't updated when the SDK is set up with the app running in the background.
#import <UIKit/UIKit.h> | ||
#elif TARGET_OS_OSX | ||
#import <AppKit/AppKit.h> | ||
#elif TARGET_OS_WATCH | ||
#import <UIKit/UIKit.h> | ||
#import <WatchKit/WatchKit.h> |
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.
watch apps have both
#elif TARGET_OS_OSX | ||
#define IS_APPLICATION_BACKGROUNDED !NSApplication.sharedApplication.isActive | ||
#elif TARGET_OS_WATCH | ||
#define IS_APPLICATION_BACKGROUNDED WKExtension.sharedExtension.applicationState == WKApplicationStateBackground |
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.
Apple's API consistency at its finest 🤪
if (!self.systemInfo.isApplicationBackgrounded) { | ||
[self updateAllCachesWithCompletionBlock:callDelegate]; | ||
} else { | ||
[self sendCachedPurchaserInfoIfAvailable]; |
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 bit is so that if there's something cached we still call the delegate. I believe this is a departure from Android. @vegaro was there a specific reason not to call the delegate there? I'm worried that not calling it is a bit inconsistent with the philosophy of sending whatever is cached as fast as we can.
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.
You're right, we should be calling in Android. I think that's what I would expect as a developer.
@@ -209,8 +209,7 @@ class PurchasesTests: XCTestCase { | |||
func setupAnonPurchases() { | |||
Purchases.automaticAppleSearchAdsAttributionCollection = false | |||
self.identityManager.mockIsAnonymous = true | |||
let systemInfo = RCSystemInfo(platformFlavor: nil, platformFlavorVersion: nil, finishTransactions: 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.
just cleanup here, this line was duplicated in a couple of places
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!
#elif TARGET_OS_OSX | ||
#define IS_APPLICATION_BACKGROUNDED !NSApplication.sharedApplication.isActive | ||
#elif TARGET_OS_WATCH | ||
#define IS_APPLICATION_BACKGROUNDED WKExtension.sharedExtension.applicationState == WKApplicationStateBackground |
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.
Nice! Much easier than in Android!
#if TARGET_OS_IOS || TARGET_OS_TV | ||
#define IS_APPLICATION_BACKGROUNDED UIApplication.sharedApplication.applicationState == UIApplicationStateBackground | ||
#elif TARGET_OS_OSX | ||
#define IS_APPLICATION_BACKGROUNDED !NSApplication.sharedApplication.isActive |
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.
in my testing, isActive
is returning nil
. I'm going to be conservative here and just return NO
for mac, since mac apps have a different lifecycle anyway.
… for NSApplication.sharedApplication.isActive is nil for whatever reason.
* Added logic to skip updating cache on setup if app is not active * inverted checks from is app active to !is app backgrounded * made the app backgrounded method an instance method to make tests easier. Added tests to check that caches aren't updated when the SDK is set up with the app running in the background. * updated value of isApplicationBackgrounded for macOS, since the value for NSApplication.sharedApplication.isActive is nil for whatever reason.
* Feature/defer cache updates if woken from push notification (#288) * Added logic to skip updating cache on setup if app is not active * inverted checks from is app active to !is app backgrounded * made the app backgrounded method an instance method to make tests easier. Added tests to check that caches aren't updated when the SDK is set up with the app running in the background. * updated value of isApplicationBackgrounded for macOS, since the value for NSApplication.sharedApplication.isActive is nil for whatever reason. * Version 3.5.2 Co-authored-by: aboedo <andresboedo@gmail.com>
Updates so that when the SDK's
configure
is called with the app in the background, it won't try to update offerings or purchaser info.They will, however, be updated if the app becomes active, per the
didBecomeActive
notification (that was already the current behavior).This also ensures that if the app is in the background and there's purchaser info cached, the purchaserInfo delegate gets called with the cached value. I believe this is different than the android behavior.
This behavior ensures that we don't make unnecessary backend calls in the following two scenarios:
Note: this is the iOS equivalent of
RevenueCat/purchases-android#94