Skip to content

Commit 6bbb89d

Browse files
authored
Merge pull request #1317 from OneSignal/5.0.0/use_cached_app_id_for_wrappers
Fix bug when setting app_id from cache
2 parents 9e74c66 + 1b73036 commit 6bbb89d

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777
#pragma clang diagnostic push
7878
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
7979

80-
/* Omit no appId error logging, for use with wrapper SDKs. */
81-
NSString* const kOSSettingsKeyInOmitNoAppIdLogging = @"kOSSettingsKeyInOmitNoAppIdLogging";
82-
8380
@interface OneSignal (SessionStatusDelegate)
8481
@end
8582

@@ -98,7 +95,6 @@ + (DelayedConsentInitializationParameters *)delayedInitParameters {
9895
return _delayedInitParameters;
9996
}
10097

101-
static NSString* appId;
10298
static NSDictionary* launchOptions;
10399
static NSDictionary* appSettings;
104100
// Ensure we only initlize the SDK once even if the public method is called more
@@ -137,10 +133,6 @@ + (OneSignalReceiveReceiptsController*)receiveReceiptsController {
137133
return _receiveReceiptsController;
138134
}
139135

140-
+ (NSString*)appId {
141-
return appId;
142-
}
143-
144136
+ (NSString*)sdkVersionRaw {
145137
return ONESIGNAL_VERSION;
146138
}
@@ -159,7 +151,6 @@ + (NSString*)sdkSemanticVersion {
159151

160152
//TODO: This is related to unit tests and will change with um tests
161153
+ (void)clearStatics {
162-
appId = nil;
163154
[OneSignalConfigManager setAppId:nil];
164155
launchOptions = false;
165156
appSettings = nil;
@@ -246,7 +237,8 @@ + (void)logout {
246237
#pragma mark Initialization
247238

248239
/*
249-
This is should be set from all OneSignal entry points.
240+
This should be set from all OneSignal entry points.
241+
Note: wrappers may call this method with a null appId.
250242
*/
251243
+ (void)initialize:(nonnull NSString*)newAppId withLaunchOptions:(nullable NSDictionary*)launchOptions {
252244
[self setAppId:newAppId];
@@ -271,30 +263,31 @@ + (NSString * _Nullable)getCachedAppId {
271263
*/
272264
// TODO: For release, note this change in migration guide:
273265
// No longer reading appID from plist @"OneSignal_APPID" and @"GameThrive_APPID"
274-
+ (void)setAppId:(nonnull NSString*)newAppId {
275-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"setAppId(id) called with appId: %@!", newAppId]];
266+
+ (void)setAppId:(nullable NSString*)newAppId {
267+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"setAppId called with appId: %@!", newAppId]];
276268

277269
if (!newAppId || newAppId.length == 0) {
278270
NSString* cachedAppId = [self getCachedAppId];
279271
if (cachedAppId) {
280-
appId = cachedAppId;
281272
[OneSignalConfigManager setAppId:cachedAppId];
282273
} else {
283274
return;
284275
}
285-
} else if (appId && ![newAppId isEqualToString:appId]) {
276+
} else if ([OneSignalConfigManager getAppId] && ![newAppId isEqualToString:[OneSignalConfigManager getAppId]]) {
286277
// Pre-check on app id to make sure init of SDK is performed properly
287278
// Usually when the app id is changed during runtime so that SDK is reinitialized properly
288279
initDone = false;
280+
[OneSignalConfigManager setAppId:newAppId];
281+
} else {
282+
[OneSignalConfigManager setAppId:newAppId];
289283
}
290-
appId = newAppId;
291-
[OneSignalConfigManager setAppId:newAppId];
292-
[self handleAppIdChange:appId];
284+
285+
[self handleAppIdChange:[OneSignalConfigManager getAppId]];
293286
}
294287

295288
+ (BOOL)isValidAppId:(NSString*)appId {
296289
if (!appId || ![[NSUUID alloc] initWithUUIDString:appId]) {
297-
[OneSignalLog onesignalLog:ONE_S_LL_FATAL message:@"OneSignal AppId format is invalid.\nExample: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'\n"];
290+
[OneSignalLog onesignalLog:ONE_S_LL_FATAL message:[NSString stringWithFormat:@"OneSignal AppId: %@ - AppId is null or format is invalid, stopping initialization.\nExample usage: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'\n", appId]];
298291
return false;
299292
}
300293
return true;
@@ -462,17 +455,16 @@ + (void)startUserManager {
462455
+ (void)delayInitializationForPrivacyConsent {
463456
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Delayed initialization of the OneSignal SDK until the user provides privacy consent using the setPrivacyConsent() method"];
464457
delayedInitializationForPrivacyConsent = true;
465-
_delayedInitParameters = [[DelayedConsentInitializationParameters alloc] initWithLaunchOptions:launchOptions withAppId:appId];
458+
_delayedInitParameters = [[DelayedConsentInitializationParameters alloc] initWithLaunchOptions:launchOptions withAppId:[OneSignalConfigManager getAppId]];
466459
// Init was not successful, set appId back to nil
467-
appId = nil;
468460
[OneSignalConfigManager setAppId:nil];
469461
}
470462

471463
/*
472464
Called after setAppId and setLaunchOptions, depending on which one is called last (order does not matter)
473465
*/
474466
+ (void)init {
475-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"setLaunchOptions(launchOptions) successful and appId is set, initializing OneSignal..."];
467+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"launchOptions is set and appId of %@ is set, initializing OneSignal...", [OneSignalConfigManager getAppId]]];
476468

477469
// TODO: We moved this check to the top of this method, we should test this.
478470
if (initDone) {
@@ -487,8 +479,8 @@ + (void)init {
487479

488480
// Wrapper SDK's call init twice and pass null as the appId on the first call
489481
// the app ID is required to download parameters, so do not download params until the appID is provided
490-
if (!_didCallDownloadParameters && appId && appId != (id)[NSNull null])
491-
[self downloadIOSParamsWithAppId:appId];
482+
if (!_didCallDownloadParameters && [OneSignalConfigManager getAppId] && [OneSignalConfigManager getAppId] != (id)[NSNull null])
483+
[self downloadIOSParamsWithAppId:[OneSignalConfigManager getAppId]];
492484

493485
// using classes as delegates is not best practice. We should consider using a shared instance of a class instead
494486
[OSSessionManager sharedSessionManager].delegate = (id<SessionStatusDelegate>)self;
@@ -501,7 +493,7 @@ + (void)init {
501493
// Now really initializing the SDK!
502494

503495
// Invalid app ids reaching here will cause failure
504-
if (![self isValidAppId:appId])
496+
if (![self isValidAppId:[OneSignalConfigManager getAppId]])
505497
return;
506498

507499
// TODO: Consider the implications of `registerUserInternal` previously running on the main_queue
@@ -719,7 +711,7 @@ + (void)sendSessionEndOutcomes:(NSNumber*)totalTimeActive params:(OSFocusCallPar
719711
}
720712

721713
[OSOutcomes.sharedController sendSessionEndOutcomes:totalTimeActive
722-
appId:appId
714+
appId:[OneSignalConfigManager getAppId]
723715
pushSubscriptionId:pushSubscriptionId
724716
onesignalId:onesignalId
725717
influenceParams:params.influenceParams

iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ typedef void (^OSFailureBlock)(NSError* error);
6363
// ======= OneSignal Class Interface =========
6464
@interface OneSignal : NSObject
6565

66-
+ (NSString*)appId;
6766
+ (NSString* _Nonnull)sdkVersionRaw;
6867
+ (NSString* _Nonnull)sdkSemanticVersion;
6968

iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ + (void)removeObserver {
7979
- (void)didBecomeActive {
8080
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene didBecomeActive"];
8181

82-
if ([OneSignal appId]) {
82+
if ([OneSignalConfigManager getAppId]) {
8383
[OneSignalTracker onFocus:NO];
8484
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
8585
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(onFocus:)]) {
@@ -95,7 +95,7 @@ - (void)didBecomeActive {
9595
- (void)willResignActive {
9696
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene willResignActive"];
9797

98-
if ([OneSignal appId]) {
98+
if ([OneSignalConfigManager getAppId]) {
9999
[OneSignalTracker onFocus:YES];
100100
// TODO: Method no longer exists, transitions into flushing operation repo on backgrounding.
101101
// [OneSignal sendTagsOnBackground];

iOS_SDK/OneSignalSDK/Source/OneSignalTracker.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ + (OSFocusCallParams *)createFocusCallParams:(NSArray<OSInfluence *> *)lastInflu
170170
[focusInfluenceParams addObject:focusInfluenceParam];
171171
}
172172

173-
return [[OSFocusCallParams alloc] initWithParamsAppId:[OneSignal appId]
173+
return [[OSFocusCallParams alloc] initWithParamsAppId:[OneSignalConfigManager getAppId]
174174
timeElapsed:timeElapsed
175175
influenceParams:focusInfluenceParams
176176
onSessionEnded:onSessionEnded];

0 commit comments

Comments
 (0)