Skip to content

Commit

Permalink
Use constants for Location and IAM module classes
Browse files Browse the repository at this point in the history
Details:
* Use constants for the 2 class names for the Location and IAM modules that are used by NSClassFromString: `OneSignalLocationManager` and `OneSignalInAppMessages`
Motivation:
* These can be easily missed. When the class `OneSignalLocation` was renamed to `OneSignalLocationManager`, some of the hardcoded strings were missed in `NSClassFromString` calls.
  • Loading branch information
nan-li committed Jan 3, 2024
1 parent 05a981d commit 68f9b7f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
// can use them directly.
#define DEFAULT_UNAUTHORIZATIONOPTIONS (UNAuthorizationOptionSound + UNAuthorizationOptionBadge + UNAuthorizationOptionAlert)

// Class Names used with NSClassFromString
#define ONE_SIGNAL_LOCATION_CLASS_NAME @"OneSignalLocationManager"
#define ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME @"OneSignalInAppMessages"

// iOS Parameter Names
#define IOS_FBA @"fba"
#define IOS_USES_PROVISIONAL_AUTHORIZATION @"uses_provisional_auth"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)handlePrompt:(void (^)(PromptActionResult result))completionHandler {
This code calls [OneSignalLocation promptLocationFallbackToSettings:true completionHandler:completionHandler];
*/
BOOL fallback = YES;
let oneSignalLocationManager = NSClassFromString(@"OneSignalLocationManager");
let oneSignalLocationManager = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocationManager != nil && [oneSignalLocationManager respondsToSelector:@selector(promptLocationFallbackToSettings:completionHandler:)]) {
NSMethodSignature* signature = [oneSignalLocationManager methodSignatureForSelector:@selector(promptLocationFallbackToSettings:completionHandler:)];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature];
Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/Source/OSMigrationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ @implementation OSMigrationController

- (void)migrate {
[self migrateToVersion_02_14_00_AndGreater];
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(migrate)]) {
[oneSignalInAppMessages performSelector:@selector(migrate)];
}
Expand Down
14 changes: 7 additions & 7 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ + (void)logout {
}

+ (Class<OSInAppMessages>)InAppMessages {
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(InAppMessages)]) {
return [oneSignalInAppMessages performSelector:@selector(InAppMessages)];
} else {
Expand All @@ -222,7 +222,7 @@ + (void)logout {
}

+ (Class<OSLocation>)Location {
let oneSignalLocationManager = NSClassFromString(@"OneSignalLocationManager");
let oneSignalLocationManager = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocationManager != nil && [oneSignalLocationManager respondsToSelector:@selector(Location)]) {
return [oneSignalLocationManager performSelector:@selector(Location)];
} else {
Expand Down Expand Up @@ -380,7 +380,7 @@ + (void)startNewSessionInternal {
[OneSignalTrackFirebaseAnalytics trackInfluenceOpenEvent];

// Clear last location after attaching data to user state or not
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(clearLastLocation)]) {
[oneSignalLocation performSelector:@selector(clearLastLocation)];
}
Expand All @@ -394,7 +394,7 @@ + (void)startNewSessionInternal {
// The OSMessagingController is an OSPushSubscriptionObserver so that we pull IAMs once we have the sub id
NSString *subscriptionId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId;
if (subscriptionId) {
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(getInAppMessagesFromServer:)]) {
[oneSignalInAppMessages performSelector:@selector(getInAppMessagesFromServer:) withObject:subscriptionId];
}
Expand All @@ -414,7 +414,7 @@ + (void)startNewSessionInternal {
}

+ (void)startInAppMessages {
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(start)]) {
[oneSignalInAppMessages performSelector:@selector(start)];
}
Expand All @@ -426,7 +426,7 @@ + (void)startOutcomes {
}

+ (void)startLocation {
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(start)]) {
[oneSignalLocation performSelector:@selector(start)];
}
Expand Down Expand Up @@ -619,7 +619,7 @@ + (void)downloadIOSParamsWithAppId:(NSString *)appId {
[[OSRemoteParamController sharedController] saveRemoteParams:result];
if ([[OSRemoteParamController sharedController] hasLocationKey]) {
BOOL shared = [result[IOS_LOCATION_SHARED] boolValue];
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(startLocationSharedWithFlag:)]) {
[OneSignalCoreHelper callSelector:@selector(startLocationSharedWithFlag:) onObject:oneSignalLocation withArg:shared];
}
Expand Down
6 changes: 3 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ - (void)didBecomeActive {

if ([OneSignalConfigManager getAppId]) {
[OneSignalTracker onFocus:NO];
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(onFocus:)]) {
[OneSignalCoreHelper callSelector:@selector(onFocus:) onObject:oneSignalLocation withArg:YES];
}
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
let oneSignalInAppMessages = NSClassFromString(ONE_SIGNAL_IN_APP_MESSAGES_CLASS_NAME);
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(onApplicationDidBecomeActive)]) {
[oneSignalInAppMessages performSelector:@selector(onApplicationDidBecomeActive)];
}
Expand All @@ -105,7 +105,7 @@ - (void)willResignActive {
- (void)didEnterBackground {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"application/scene didEnterBackground"];
if ([OneSignalConfigManager getAppId]) {
let oneSignalLocation = NSClassFromString(@"OneSignalLocation");
let oneSignalLocation = NSClassFromString(ONE_SIGNAL_LOCATION_CLASS_NAME);
if (oneSignalLocation != nil && [oneSignalLocation respondsToSelector:@selector(onFocus:)]) {
[OneSignalCoreHelper callSelector:@selector(onFocus:) onObject:oneSignalLocation withArg:NO];
}
Expand Down

0 comments on commit 68f9b7f

Please sign in to comment.