Skip to content

Commit

Permalink
Execute publishinstall in main thread
Browse files Browse the repository at this point in the history
Summary: Execute publishinstall in main thread to avoid the edge cases of duplicate install publish

Reviewed By: jjiang10

Differential Revision: D57845995

fbshipit-source-id: 02491aa26fcd08fe4ce82fa66969be8831ab2d54
  • Loading branch information
Zilin Zhang authored and facebook-github-bot committed May 29, 2024
1 parent ad43e68 commit e6f65ca
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ - (void)activateApp

[self.appEventsUtility ensureOnMainThread:NSStringFromSelector(_cmd) className:NSStringFromClass(self.class)];

// Fetch app settings and register for transaction notifications only if app supports implicit purchase
// events
// Fetch app settings and register for transaction notifications only if app supports implicit purchase events
[self publishInstall];
[self fetchServerConfiguration:NULL];

Expand Down Expand Up @@ -849,39 +848,41 @@ - (void)publishInstall
[self.logger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"Missing [FBSDKAppEvents appID] for [FBSDKAppEvents publishInstall:]"];
return;
}
NSString *lastAttributionPingString = [NSString stringWithFormat:@"com.facebook.sdk:lastAttributionPing%@", appID];
if ([self.primaryDataStore fb_objectForKey:lastAttributionPingString]) {
return;
}
[self.primaryDataStore fb_setObject:[NSDate date] forKey:lastAttributionPingString];
[self fetchServerConfiguration:^{
if ([self.appEventsUtility shouldDropAppEvents] || [self.gateKeeperManager boolForKey:FBSDKGateKeeperAppEventsKillSwitch defaultValue:NO]) {
fb_dispatch_on_main_thread(^{
NSString *lastAttributionPingString = [NSString stringWithFormat:@"com.facebook.sdk:lastAttributionPing%@", appID];
if ([self.primaryDataStore fb_objectForKey:lastAttributionPingString]) {
return;
}
NSMutableDictionary<NSString *, NSString *> *params = [self.appEventsUtility activityParametersDictionaryForEvent:@"MOBILE_APP_INSTALL"
shouldAccessAdvertisingID:self.serverConfiguration.isAdvertisingIDEnabled
userID:self.userID
userData:[self getUserData]];
[self appendInstallTimestamp:params];
[self.capiReporter recordEvent:params];
NSString *path = [NSString stringWithFormat:@"%@/activities", appID];
id<FBSDKGraphRequest> request = [self.graphRequestFactory createGraphRequestWithGraphPath:path
parameters:params
tokenString:nil
HTTPMethod:FBSDKHTTPMethodPOST
flags:FBSDKGraphRequestFlagDoNotInvalidateTokenOnError | FBSDKGraphRequestFlagDisableErrorRecovery
forAppEvents:YES
useAlternativeDefaultDomainPrefix:NO];
__block id<FBSDKDataPersisting> weakStore = self.primaryDataStore;
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
if (!error) {
NSString *lastInstallResponseKey = [NSString stringWithFormat:@"com.facebook.sdk:lastInstallResponse%@", appID];
[weakStore fb_setObject:result forKey:lastInstallResponseKey];
} else {
[weakStore fb_removeObjectForKey:lastAttributionPingString];
[self.primaryDataStore fb_setObject:[NSDate date] forKey:lastAttributionPingString];
[self fetchServerConfiguration:^{
if ([self.appEventsUtility shouldDropAppEvents] || [self.gateKeeperManager boolForKey:FBSDKGateKeeperAppEventsKillSwitch defaultValue:NO]) {
return;
}
NSMutableDictionary<NSString *, NSString *> *params = [self.appEventsUtility activityParametersDictionaryForEvent:@"MOBILE_APP_INSTALL"
shouldAccessAdvertisingID:self.serverConfiguration.isAdvertisingIDEnabled
userID:self.userID
userData:[self getUserData]];
[self appendInstallTimestamp:params];
[self.capiReporter recordEvent:params];
NSString *path = [NSString stringWithFormat:@"%@/activities", appID];
id<FBSDKGraphRequest> request = [self.graphRequestFactory createGraphRequestWithGraphPath:path
parameters:params
tokenString:nil
HTTPMethod:FBSDKHTTPMethodPOST
flags:FBSDKGraphRequestFlagDoNotInvalidateTokenOnError | FBSDKGraphRequestFlagDisableErrorRecovery
forAppEvents:YES
useAlternativeDefaultDomainPrefix:NO];
__block id<FBSDKDataPersisting> weakStore = self.primaryDataStore;
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
if (!error) {
NSString *lastInstallResponseKey = [NSString stringWithFormat:@"com.facebook.sdk:lastInstallResponse%@", appID];
[weakStore fb_setObject:result forKey:lastInstallResponseKey];
} else {
[weakStore fb_removeObjectForKey:lastAttributionPingString];
}
}];
}];
}];
});
}

- (void)publishATE
Expand Down

0 comments on commit e6f65ca

Please sign in to comment.