From 5046fcce7983a6d91d36b2309309fe24ec5ed5f3 Mon Sep 17 00:00:00 2001 From: Nickolas Dimitrakas Date: Fri, 24 Oct 2025 17:59:14 -0400 Subject: [PATCH 1/5] Created app environment provider --- UnitTests/MParticle+PrivateMethods.h | 2 +- mParticle-Apple-SDK.xcodeproj/project.pbxproj | 12 ++++++++++++ mParticle-Apple-SDK/AppEnvironmentProvider.h | 9 +++++++++ mParticle-Apple-SDK/AppEnvironmentProvider.m | 12 ++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 mParticle-Apple-SDK/AppEnvironmentProvider.h create mode 100644 mParticle-Apple-SDK/AppEnvironmentProvider.m diff --git a/UnitTests/MParticle+PrivateMethods.h b/UnitTests/MParticle+PrivateMethods.h index 79742e6f8..956caca12 100644 --- a/UnitTests/MParticle+PrivateMethods.h +++ b/UnitTests/MParticle+PrivateMethods.h @@ -50,5 +50,5 @@ @property (nonatomic, strong, nonnull) id listenerController; @property (nonatomic, strong) id stateMachine; @property (nonatomic, strong) id persistenceController; +@property (nonatomic, strong, nonnull) id appEnvironmentProvider; @end - diff --git a/mParticle-Apple-SDK.xcodeproj/project.pbxproj b/mParticle-Apple-SDK.xcodeproj/project.pbxproj index adf0801ed..a567c71e6 100644 --- a/mParticle-Apple-SDK.xcodeproj/project.pbxproj +++ b/mParticle-Apple-SDK.xcodeproj/project.pbxproj @@ -506,6 +506,10 @@ 53E20DC82CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */; }; 53FDD1BD2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; }; 53FDD1BE2AE871AF003D5FA1 /* MPIHasher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */; }; + 729721762EAC2AD60045E55C /* AppEnvironmentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */; }; + 729721772EAC2AD60045E55C /* AppEnvironmentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */; }; + 729721792EAC2B750045E55C /* AppEnvironmentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 729721782EAC2B750045E55C /* AppEnvironmentProvider.m */; }; + 7297217A2EAC2B750045E55C /* AppEnvironmentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 729721782EAC2B750045E55C /* AppEnvironmentProvider.m */; }; 72D356532E84601A0012A0C2 /* MPEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72D356522E8460020012A0C2 /* MPEventTests.swift */; }; 72D356542E84601A0012A0C2 /* MPEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72D356522E8460020012A0C2 /* MPEventTests.swift */; }; 72FEBD172E86FE3B00B8341F /* MPIdentityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72FEBD162E86FE2D00B8341F /* MPIdentityTests.swift */; }; @@ -843,6 +847,8 @@ 53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPSideloadedKit.swift; sourceTree = ""; }; 53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+MPCaseInsensitiveTests.swift"; sourceTree = ""; }; 53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = ""; }; + 729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppEnvironmentProvider.h; sourceTree = ""; }; + 729721782EAC2B750045E55C /* AppEnvironmentProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppEnvironmentProvider.m; sourceTree = ""; }; 72D356522E8460020012A0C2 /* MPEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPEventTests.swift; sourceTree = ""; }; 72FEBD162E86FE2D00B8341F /* MPIdentityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIdentityTests.swift; sourceTree = ""; }; 7E03877F2DB913D2003B7D5E /* MPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPRokt.h; sourceTree = ""; }; @@ -951,6 +957,8 @@ isa = PBXGroup; children = ( 3513083F2E6B28F5002A3AD6 /* Executor.h */, + 729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */, + 729721782EAC2B750045E55C /* AppEnvironmentProvider.m */, 351308402E6B28F5002A3AD6 /* Executor.m */, 53A79C2229CDFB4800E7489F /* Include */, 53A79B3629CDFB1F00E7489F /* mParticle.m */, @@ -1479,6 +1487,7 @@ 53A79C1E29CDFB2100E7489F /* MPKitFilter.h in Headers */, 53A79C1529CDFB2100E7489F /* MPDataPlanFilter.h in Headers */, 531BCF342B28A23400F5C573 /* MPIdentityCaching.h in Headers */, + 729721772EAC2AD60045E55C /* AppEnvironmentProvider.h in Headers */, 53A79C0029CDFB2100E7489F /* MPPromotion+Dictionary.h in Headers */, 53A79B9229CDFB2000E7489F /* MPBreadcrumb.h in Headers */, 53A79B7B29CDFB2000E7489F /* MPConnectorProtocol.h in Headers */, @@ -1575,6 +1584,7 @@ 53A79D4C29CE23F700E7489F /* MPDataPlanFilter.h in Headers */, 531BCF352B28A23400F5C573 /* MPIdentityCaching.h in Headers */, 53A79D4D29CE23F700E7489F /* MPPromotion+Dictionary.h in Headers */, + 729721762EAC2AD60045E55C /* AppEnvironmentProvider.h in Headers */, 53A79D4E29CE23F700E7489F /* MPBreadcrumb.h in Headers */, 53A79D4F29CE23F700E7489F /* MPConnectorProtocol.h in Headers */, 53A79D5029CE23F700E7489F /* MPBracket.h in Headers */, @@ -1906,6 +1916,7 @@ 53A79BC029CDFB2000E7489F /* MPConsentKitFilter.m in Sources */, 53A79C0A29CDFB2100E7489F /* MPKitRegister.m in Sources */, 35E3FCD02E54978C00DB5B18 /* MParticleSession+MParticlePrivate.m in Sources */, + 7297217A2EAC2B750045E55C /* AppEnvironmentProvider.m in Sources */, 534C11B42D08A73700466F71 /* MParticleWebView.swift in Sources */, 53A79B9429CDFB2000E7489F /* MPForwardRecord.m in Sources */, D3BE919B2D5B96700038C87A /* MPLaunchInfo.swift in Sources */, @@ -2101,6 +2112,7 @@ 53A79D9029CE23F700E7489F /* MPDatabaseMigrationController.m in Sources */, 53A79D9129CE23F700E7489F /* MPConsentKitFilter.m in Sources */, 35E3FCCF2E54978C00DB5B18 /* MParticleSession+MParticlePrivate.m in Sources */, + 729721792EAC2B750045E55C /* AppEnvironmentProvider.m in Sources */, 534C11B32D08A73700466F71 /* MParticleWebView.swift in Sources */, 53A79D9229CE23F700E7489F /* MPKitRegister.m in Sources */, D3BE919C2D5B96700038C87A /* MPLaunchInfo.swift in Sources */, diff --git a/mParticle-Apple-SDK/AppEnvironmentProvider.h b/mParticle-Apple-SDK/AppEnvironmentProvider.h new file mode 100644 index 000000000..49b31876f --- /dev/null +++ b/mParticle-Apple-SDK/AppEnvironmentProvider.h @@ -0,0 +1,9 @@ +#import + +@protocol AppEnvironmentProviderProtocol +- (BOOL)isAppExtension; +@end + +@interface AppEnvironmentProvider : NSObject +- (BOOL)isAppExtension; +@end diff --git a/mParticle-Apple-SDK/AppEnvironmentProvider.m b/mParticle-Apple-SDK/AppEnvironmentProvider.m new file mode 100644 index 000000000..a83a31c3a --- /dev/null +++ b/mParticle-Apple-SDK/AppEnvironmentProvider.m @@ -0,0 +1,12 @@ +#import "AppEnvironmentProvider.h" + +@implementation AppEnvironmentProvider + +- (BOOL)isAppExtension { +#if TARGET_OS_IOS == 1 + return [[NSBundle mainBundle].bundlePath hasSuffix:@".appex"]; +#else + return NO; +#endif +} +@end From 448f0e0347e8d593ff0c622a88860a2b3458122a Mon Sep 17 00:00:00 2001 From: Nickolas Dimitrakas Date: Fri, 24 Oct 2025 18:09:10 -0400 Subject: [PATCH 2/5] replaced usage of static methods in mP.m --- mParticle-Apple-SDK/mParticle.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index 4a3971c1c..0831b8b61 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -18,6 +18,7 @@ #import "MParticleOptions+MParticlePrivate.h" #import "SettingsProvider.h" #import "Executor.h" +#import "AppEnvironmentProvider.h" static NSArray *eventTypeStrings = nil; static MParticle *_sharedInstance = nil; @@ -68,10 +69,9 @@ @interface MParticle() settingsProvider; @property (nonatomic, strong, nonnull) id listenerController; - +@property (nonatomic, strong, nonnull) id appEnvironmentProvider; @end - @implementation MPDataPlanOptions @end @@ -152,6 +152,7 @@ - (instancetype)init { _stateMachine = [[MPStateMachine_PRIVATE alloc] init]; _webView = [[MParticleWebView_PRIVATE alloc] initWithMessageQueue:executor.messageQueue]; _listenerController = MPListenerController.sharedInstance; + _appEnvironmentProvider = [[AppEnvironmentProvider alloc] init]; logger = [[MPLog alloc] initWithLogLevel:_stateMachine.logLevel]; return self; @@ -606,7 +607,7 @@ - (void)switchWorkspaceWithOptions:(MParticleOptions *)options { #pragma mark Application notifications #if TARGET_OS_IOS == 1 - (NSData *)pushNotificationToken { - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { return [MPNotificationController_PRIVATE deviceToken]; } else { return nil; @@ -614,7 +615,7 @@ - (NSData *)pushNotificationToken { } - (void)setPushNotificationToken:(NSData *)pushNotificationToken { - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [MPNotificationController_PRIVATE setDeviceToken:pushNotificationToken]; } } @@ -624,7 +625,7 @@ - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo { return; } - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [[MParticle sharedInstance].appNotificationHandler didReceiveRemoteNotification:userInfo]; } } @@ -634,7 +635,7 @@ - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { return; } - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [[MParticle sharedInstance].appNotificationHandler didFailToRegisterForRemoteNotificationsWithError:error]; } } @@ -644,7 +645,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { return; } - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [[MParticle sharedInstance].appNotificationHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } } @@ -654,7 +655,7 @@ - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification: return; } - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [[MParticle sharedInstance].appNotificationHandler handleActionWithIdentifier:identifier forRemoteNotification:userInfo]; } } @@ -664,7 +665,7 @@ - (void)handleActionWithIdentifier:(nullable NSString *)identifier forRemoteNoti return; } - if (![MPStateMachine_PRIVATE isAppExtension]) { + if (![self.appEnvironmentProvider isAppExtension]) { [[MParticle sharedInstance].appNotificationHandler handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo]; } } From d65bfe6794983ce100715663e63c6b5ff1bcf38d Mon Sep 17 00:00:00 2001 From: Nickolas Dimitrakas Date: Fri, 24 Oct 2025 18:36:43 -0400 Subject: [PATCH 3/5] Create protocol for MPNotificationController switched from static methods --- UnitTests/MParticle+PrivateMethods.h | 1 + .../Include/MPNotificationController.h | 15 ++++++++++++--- .../Notifications/MPNotificationController.m | 11 +++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/UnitTests/MParticle+PrivateMethods.h b/UnitTests/MParticle+PrivateMethods.h index 956caca12..f7e9c2783 100644 --- a/UnitTests/MParticle+PrivateMethods.h +++ b/UnitTests/MParticle+PrivateMethods.h @@ -50,5 +50,6 @@ @property (nonatomic, strong, nonnull) id listenerController; @property (nonatomic, strong) id stateMachine; @property (nonatomic, strong) id persistenceController; +@property (nonatomic, strong, nullable) id notificationController; @property (nonatomic, strong, nonnull) id appEnvironmentProvider; @end diff --git a/mParticle-Apple-SDK/Include/MPNotificationController.h b/mParticle-Apple-SDK/Include/MPNotificationController.h index 65ad20258..7320023cf 100644 --- a/mParticle-Apple-SDK/Include/MPNotificationController.h +++ b/mParticle-Apple-SDK/Include/MPNotificationController.h @@ -1,11 +1,20 @@ #import #import -@interface MPNotificationController_PRIVATE : NSObject +@protocol MPNotificationControllerProtocol #if TARGET_OS_IOS == 1 -+ (nullable NSData *)deviceToken; -+ (void)setDeviceToken:(nullable NSData *)devToken; +- (nullable NSData *)deviceToken; +- (void)setDeviceToken:(nullable NSData *)devToken; +#endif + +@end + +@interface MPNotificationController_PRIVATE : NSObject + +#if TARGET_OS_IOS == 1 +- (nullable NSData *)deviceToken; +- (void)setDeviceToken:(nullable NSData *)devToken; #endif @end diff --git a/mParticle-Apple-SDK/Notifications/MPNotificationController.m b/mParticle-Apple-SDK/Notifications/MPNotificationController.m index 2a5574946..822310842 100644 --- a/mParticle-Apple-SDK/Notifications/MPNotificationController.m +++ b/mParticle-Apple-SDK/Notifications/MPNotificationController.m @@ -5,11 +5,6 @@ #import "MPNetworkCommunication.h" #import "MParticleSwift.h" -@interface MPNotificationController_PRIVATE() { -} - -@end - @interface MParticle () + (dispatch_queue_t)messageQueue; @@ -36,7 +31,7 @@ - (instancetype)init { } #pragma mark Public static methods -+ (NSData *)deviceToken { +- (NSData *)deviceToken { #ifndef MP_UNIT_TESTING MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity]; deviceToken = userDefaults[kMPDeviceTokenKey]; @@ -47,8 +42,8 @@ + (NSData *)deviceToken { return deviceToken; } -+ (void)setDeviceToken:(NSData *)devToken { - if ([MPNotificationController_PRIVATE deviceToken] && [[MPNotificationController_PRIVATE deviceToken] isEqualToData:devToken]) { +- (void)setDeviceToken:(NSData *)devToken { + if ([deviceToken isEqualToData:devToken]) { return; } From 262d0f33263ac07cf24d514ea12cebab05990812 Mon Sep 17 00:00:00 2001 From: Nickolas Dimitrakas Date: Fri, 24 Oct 2025 18:37:43 -0400 Subject: [PATCH 4/5] replaced usage of notif controller static methods --- .../AppNotifications/MPAppNotificationHandler.m | 6 ++++-- mParticle-Apple-SDK/Identity/MPIdentityDTO.m | 3 ++- mParticle-Apple-SDK/MPBackendController.m | 2 +- mParticle-Apple-SDK/Utils/MPDevice.swift | 3 ++- mParticle-Apple-SDK/mParticle.m | 6 ++++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m index 3bf07b816..ced7bdccd 100644 --- a/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m +++ b/mParticle-Apple-SDK/AppNotifications/MPAppNotificationHandler.m @@ -55,7 +55,8 @@ - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { } if (![MPStateMachine_PRIVATE isAppExtension]) { - [MPNotificationController_PRIVATE setDeviceToken:nil]; + MPNotificationController_PRIVATE *notificationController = [[MPNotificationController_PRIVATE alloc] init]; + [notificationController setDeviceToken:nil]; } SEL failedRegistrationSelector = @selector(failedToRegisterForUserNotifications:); @@ -89,7 +90,8 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { } if (![MPStateMachine_PRIVATE isAppExtension]) { - [MPNotificationController_PRIVATE setDeviceToken:deviceToken]; + MPNotificationController_PRIVATE *notificationController = [[MPNotificationController_PRIVATE alloc] init]; + [notificationController setDeviceToken:deviceToken]; } SEL deviceTokenSelector = @selector(setDeviceToken:); diff --git a/mParticle-Apple-SDK/Identity/MPIdentityDTO.m b/mParticle-Apple-SDK/Identity/MPIdentityDTO.m index 85e9d2733..b84bb9b2e 100644 --- a/mParticle-Apple-SDK/Identity/MPIdentityDTO.m +++ b/mParticle-Apple-SDK/Identity/MPIdentityDTO.m @@ -73,7 +73,8 @@ - (instancetype)initWithIdentityApiRequest:(MPIdentityApiRequest *)apiRequest { #if TARGET_OS_IOS == 1 if (![MPStateMachine_PRIVATE isAppExtension]) { - NSData *deviceTokenData = [MPNotificationController_PRIVATE deviceToken]; + MPNotificationController_PRIVATE *notificationController = [[MPNotificationController_PRIVATE alloc] init]; + NSData *deviceTokenData = [notificationController deviceToken]; if (deviceTokenData) { NSString *deviceTokenString = [MPUserDefaults stringFromDeviceToken:deviceTokenData]; if (deviceTokenString && [deviceTokenString length] > 0) { diff --git a/mParticle-Apple-SDK/MPBackendController.m b/mParticle-Apple-SDK/MPBackendController.m index 8af2e1dd9..9c6e66db7 100644 --- a/mParticle-Apple-SDK/MPBackendController.m +++ b/mParticle-Apple-SDK/MPBackendController.m @@ -1959,7 +1959,7 @@ - (void)logUserNotification:(MParticleUserNotification *)userNotification { kMPPushMessageTypeKey:userNotification.type} mutableCopy]; - NSString *tokenString = [MPUserDefaults stringFromDeviceToken:[MPNotificationController_PRIVATE deviceToken]]; + NSString *tokenString = [MPUserDefaults stringFromDeviceToken:[self.notificationController deviceToken]]; if (tokenString) { messageInfo[kMPDeviceTokenKey] = tokenString; } diff --git a/mParticle-Apple-SDK/Utils/MPDevice.swift b/mParticle-Apple-SDK/Utils/MPDevice.swift index 13adf7586..730523f1b 100644 --- a/mParticle-Apple-SDK/Utils/MPDevice.swift +++ b/mParticle-Apple-SDK/Utils/MPDevice.swift @@ -362,7 +362,8 @@ public class MPDevice: NSObject, NSCopying { #if os(iOS) && !MPARTICLE_LOCATION_DISABLE deviceDictionary[Device.kMPDeviceRadioKey] = radioAccessTechnology - if let pushNotificationToken = MPNotificationController_PRIVATE.deviceToken() { + let notificationController = MPNotificationController_PRIVATE() + if let pushNotificationToken = notificationController.deviceToken() { if let tokenString = MPUserDefaults.stringFromDeviceToken(pushNotificationToken) { deviceDictionary[PushNotifications.kMPDeviceTokenKey] = tokenString } diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index 0831b8b61..d6d60c3d0 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -608,7 +608,8 @@ - (void)switchWorkspaceWithOptions:(MParticleOptions *)options { #if TARGET_OS_IOS == 1 - (NSData *)pushNotificationToken { if (![self.appEnvironmentProvider isAppExtension]) { - return [MPNotificationController_PRIVATE deviceToken]; + MPNotificationController_PRIVATE* notificationController = [[MPNotificationController_PRIVATE alloc] init]; + return [notificationController deviceToken]; } else { return nil; } @@ -616,7 +617,8 @@ - (NSData *)pushNotificationToken { - (void)setPushNotificationToken:(NSData *)pushNotificationToken { if (![self.appEnvironmentProvider isAppExtension]) { - [MPNotificationController_PRIVATE setDeviceToken:pushNotificationToken]; + MPNotificationController_PRIVATE* notificationController = [[MPNotificationController_PRIVATE alloc] init]; + [notificationController setDeviceToken:pushNotificationToken]; } } From 982ce689d00410a38dc09735023e82cf6ba51354 Mon Sep 17 00:00:00 2001 From: Nickolas Dimitrakas Date: Fri, 24 Oct 2025 18:43:04 -0400 Subject: [PATCH 5/5] removed initialization from methods to class init --- mParticle-Apple-SDK/mParticle.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mParticle-Apple-SDK/mParticle.m b/mParticle-Apple-SDK/mParticle.m index d6d60c3d0..37b26d1c9 100644 --- a/mParticle-Apple-SDK/mParticle.m +++ b/mParticle-Apple-SDK/mParticle.m @@ -70,6 +70,7 @@ @interface MParticle() settingsProvider; @property (nonatomic, strong, nonnull) id listenerController; @property (nonatomic, strong, nonnull) id appEnvironmentProvider; +@property (nonatomic, strong, nonnull) id notificationController; @end @implementation MPDataPlanOptions @@ -153,6 +154,7 @@ - (instancetype)init { _webView = [[MParticleWebView_PRIVATE alloc] initWithMessageQueue:executor.messageQueue]; _listenerController = MPListenerController.sharedInstance; _appEnvironmentProvider = [[AppEnvironmentProvider alloc] init]; + _notificationController = [[MPNotificationController_PRIVATE alloc] init]; logger = [[MPLog alloc] initWithLogLevel:_stateMachine.logLevel]; return self; @@ -608,8 +610,7 @@ - (void)switchWorkspaceWithOptions:(MParticleOptions *)options { #if TARGET_OS_IOS == 1 - (NSData *)pushNotificationToken { if (![self.appEnvironmentProvider isAppExtension]) { - MPNotificationController_PRIVATE* notificationController = [[MPNotificationController_PRIVATE alloc] init]; - return [notificationController deviceToken]; + return [self.notificationController deviceToken]; } else { return nil; } @@ -617,8 +618,7 @@ - (NSData *)pushNotificationToken { - (void)setPushNotificationToken:(NSData *)pushNotificationToken { if (![self.appEnvironmentProvider isAppExtension]) { - MPNotificationController_PRIVATE* notificationController = [[MPNotificationController_PRIVATE alloc] init]; - [notificationController setDeviceToken:pushNotificationToken]; + [self.notificationController setDeviceToken:pushNotificationToken]; } }