From f8b34a3cb0b732abf3187de1df60283c4171ae7b Mon Sep 17 00:00:00 2001 From: Peter Kristensen Date: Mon, 1 Mar 2021 11:52:15 +0100 Subject: [PATCH] Fix missing token bug for App Events --- CHANGELOG.md | 2 ++ .../AppEvents/Internal/FBSDKAppEventsUtility.m | 2 +- .../Internal/AppEvents/FBSDKAppEventsUtilityTests.m | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d97a65c0f..b6c9acb8bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +- App Events use the correct token if none have been provided manually + ### Important [Full Changelog](https://github.com/facebook/facebook-ios-sdk/compare/v9.1.0...HEAD) diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKAppEventsUtility.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKAppEventsUtility.m index a8535a4145..d1444b1b3b 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKAppEventsUtility.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKAppEventsUtility.m @@ -319,7 +319,7 @@ + (NSString *)tokenStringToUseFor:(FBSDKAccessToken *)token // If there's an logging override app id present, then we don't want to use the client token since the client token // is intended to match up with the primary app id (and AppEvents doesn't require a client token). NSString *clientTokenString = [FBSDKSettings clientToken]; - if (clientTokenString && appID && [appID isEqualToString:token.appID]) { + if (clientTokenString && appID && ([appID isEqualToString:token.appID] || token == nil)) { tokenString = [NSString stringWithFormat:@"%@|%@", appID, clientTokenString]; } else if (appID) { tokenString = nil; diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/FBSDKAppEventsUtilityTests.m b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/FBSDKAppEventsUtilityTests.m index d46d5d3656..0ae46a6f27 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/FBSDKAppEventsUtilityTests.m +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/FBSDKAppEventsUtilityTests.m @@ -317,4 +317,13 @@ - (void)testGetStandardEvents } } +- (void)testProvideTokenForAppAndClient +{ + [FBSDKAppEvents setLoggingOverrideAppID:nil]; + [FBSDKSettings setAppID:@"123"]; + [FBSDKSettings setClientToken:@"toktok"]; + NSString *token = [FBSDKAppEventsUtility tokenStringToUseFor:nil]; + XCTAssertEqualObjects(@"123|toktok", token); +} + @end