Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/build-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-project "mParticle-Apple-SDK.xcodeproj" \
-scheme "mParticle-Apple-SDK" \
-destination "generic/platform=iOS" \
OTHER_CFLAGS="-Wno-deprecated-declarations" \
clean build | xcpretty

- name: Build SDK NoLocation
Expand All @@ -62,6 +63,7 @@ jobs:
-project "mParticle-Apple-SDK.xcodeproj" \
-scheme "mParticle-Apple-SDK-NoLocation" \
-destination "generic/platform=iOS" \
OTHER_CFLAGS="-Wno-deprecated-declarations" \
clean build | xcpretty

run-analyzer:
Expand All @@ -75,7 +77,25 @@ jobs:

- name: Run static analyzer
run: |
bash -c '! (set -o pipefail && xcodebuild -project "mParticle-Apple-SDK.xcodeproj" -scheme "mParticle-Apple-SDK" -sdk iphonesimulator -configuration Debug -destination "platform=iOS Simulator,name=iPhone 16 Pro,OS=latest" clean analyze | grep -v "warning: The iOS Simulator deployment target" | grep -v "warning: Metadata extraction skipped" | grep -F -v "Repeated use of MParticle sharedInstance in one method; assign to a local variable once." | grep -F -v "warning: Run script build phase '"'"'Run Script'"'"' will be run during every build" | grep -B3 "warning")'
! (set -o pipefail && xcodebuild \
-project "mParticle-Apple-SDK.xcodeproj" \
-scheme "mParticle-Apple-SDK" \
-sdk iphonesimulator \
-configuration Debug \
-destination "platform=iOS Simulator,name=iPhone 16 Pro,OS=latest" \
clean analyze \
| grep -v "warning: The iOS Simulator deployment target" \
| grep -v "warning: Metadata extraction skipped" \
| grep -F -v "Repeated use of MParticle sharedInstance in one method; assign to a local variable once." \
| grep -F -v "warning: Run script build phase 'Run Script' will be run during every build" \
| grep -v "setDeviceToken" \
| grep -v "warning: '.*' is deprecated" \
| grep -v "deprecated" \
| grep -v "AvailabilityMacros.h" \
| grep -v "\[-Wdeprecated-declarations\]" \
| grep -v "Use the instance method defined in the AppEnvironmentProvider" \
| grep -B3 "warning")


pr-notify:
if: >
Expand Down
4 changes: 3 additions & 1 deletion UnitTests/MParticle+PrivateMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "MParticleSwift.h"
#import "MPDataPlanFilter.h"
#import "MPListenerController.h"
#import "AppEnvironmentProvider.h"

@interface MParticle (Tests)
- (void)setOptOutCompletion:(MPExecStatus)execStatus optOut:(BOOL)optOut;
Expand Down Expand Up @@ -50,5 +51,6 @@
@property (nonatomic, strong, nonnull) id<MPListenerControllerProtocol> listenerController;
@property (nonatomic, strong) id<MPStateMachineProtocol> stateMachine;
@property (nonatomic, strong) id<MPPersistenceControllerProtocol> persistenceController;
@property (nonatomic, strong, nonnull) id<MPNotificationControllerProtocol> notificationController;
@property (nonatomic, strong, nonnull) id<AppEnvironmentProviderProtocol> appEnvironmentProvider;
@end

1 change: 1 addition & 0 deletions UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
#import "MPKitConfiguration.h"
#import "MPForwardRecord.h"
#import "MPIntegrationAttributes.h"
#import "AppEnvironmentProvider.h"
12 changes: 12 additions & 0 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -843,6 +847,8 @@
53B33E892A4606CD00CC8A19 /* MPSideloadedKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPSideloadedKit.swift; sourceTree = "<group>"; };
53E20DC62CBFFCD200146A97 /* NSArray+MPCaseInsensitiveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSArray+MPCaseInsensitiveTests.swift"; sourceTree = "<group>"; };
53FDD1BC2AE871AF003D5FA1 /* MPIHasher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIHasher.swift; sourceTree = "<group>"; };
729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppEnvironmentProvider.h; sourceTree = "<group>"; };
729721782EAC2B750045E55C /* AppEnvironmentProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppEnvironmentProvider.m; sourceTree = "<group>"; };
72D356522E8460020012A0C2 /* MPEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPEventTests.swift; sourceTree = "<group>"; };
72FEBD162E86FE2D00B8341F /* MPIdentityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPIdentityTests.swift; sourceTree = "<group>"; };
7E03877F2DB913D2003B7D5E /* MPRokt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPRokt.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -951,6 +957,8 @@
isa = PBXGroup;
children = (
3513083F2E6B28F5002A3AD6 /* Executor.h */,
729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */,
729721782EAC2B750045E55C /* AppEnvironmentProvider.m */,
351308402E6B28F5002A3AD6 /* Executor.m */,
53A79C2229CDFB4800E7489F /* Include */,
53A79B3629CDFB1F00E7489F /* mParticle.m */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
9 changes: 9 additions & 0 deletions mParticle-Apple-SDK/AppEnvironmentProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <Foundation/Foundation.h>

@protocol AppEnvironmentProviderProtocol
- (BOOL)isAppExtension;
@end

@interface AppEnvironmentProvider : NSObject<AppEnvironmentProviderProtocol>
- (BOOL)isAppExtension;
@end
12 changes: 12 additions & 0 deletions mParticle-Apple-SDK/AppEnvironmentProvider.m
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion mParticle-Apple-SDK/Include/MPNotificationController.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@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 <MPNotificationControllerProtocol>

#if TARGET_OS_IOS == 1
+ (nullable NSData *)deviceToken;// DEPRECATED_MSG_ATTRIBUTE("This method is no longer static. Use an instance method instead.");
+ (void)setDeviceToken:(nullable NSData *)devToken DEPRECATED_MSG_ATTRIBUTE("This method is no longer static. Use an instance method instead.");
- (nullable NSData *)deviceToken;
- (void)setDeviceToken:(nullable NSData *)devToken;
#endif

@end
2 changes: 1 addition & 1 deletion mParticle-Apple-SDK/Include/MPStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
+ (nullable NSString *)provisioningProfileString;
+ (BOOL)runningInBackground;
+ (void)setRunningInBackground:(BOOL)background;
+ (BOOL)isAppExtension;
+ (BOOL)isAppExtension; //DEPRECATED_MSG_ATTRIBUTE("Use the instance method defined in the AppEnvironmentProvider instead.");
- (void)configureCustomModules:(nullable NSArray<NSDictionary *> *)customModuleSettings;
- (void)configureRampPercentage:(nullable NSNumber *)rampPercentage;
- (void)configureTriggers:(nullable NSDictionary *)triggerDictionary;
Expand Down
26 changes: 17 additions & 9 deletions mParticle-Apple-SDK/Notifications/MPNotificationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#import "MPNetworkCommunication.h"
#import "MParticleSwift.h"

@interface MPNotificationController_PRIVATE() {
}

@end

@interface MParticle ()

+ (dispatch_queue_t)messageQueue;
Expand All @@ -35,8 +30,8 @@ - (instancetype)init {
return self;
}

#pragma mark Public static methods
+ (NSData *)deviceToken {
#pragma mark Instance methods
- (NSData *)deviceToken {
#ifndef MP_UNIT_TESTING
MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine:[MParticle sharedInstance].stateMachine backendController:[MParticle sharedInstance].backendController identity:[MParticle sharedInstance].identity];
deviceToken = userDefaults[kMPDeviceTokenKey];
Expand All @@ -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;
}

Expand Down Expand Up @@ -89,6 +84,19 @@ + (void)setDeviceToken:(NSData *)devToken {
});
}

#pragma mark Deprecated static methods
+ (NSData *)deviceToken {
// Deprecated: Delegates to instance method
MPNotificationController_PRIVATE *controller = [[MPNotificationController_PRIVATE alloc] init];
return [controller deviceToken];
}

+ (void)setDeviceToken:(NSData *)devToken {
// Deprecated: Delegates to instance method
MPNotificationController_PRIVATE *controller = [[MPNotificationController_PRIVATE alloc] init];
[controller setDeviceToken:devToken];
}

#endif

@end
25 changes: 14 additions & 11 deletions mParticle-Apple-SDK/mParticle.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,10 +69,10 @@ @interface MParticle() <MPBackendControllerDelegate

@property (nonatomic, strong) id<SettingsProviderProtocol> settingsProvider;
@property (nonatomic, strong, nonnull) id<MPListenerControllerProtocol> listenerController;

@property (nonatomic, strong, nonnull) id<MPNotificationControllerProtocol> notificationController;
@property (nonatomic, strong, nonnull) id<AppEnvironmentProviderProtocol> appEnvironmentProvider;
@end


@implementation MPDataPlanOptions
@end

Expand Down Expand Up @@ -152,6 +153,8 @@ - (instancetype)init {
_stateMachine = [[MPStateMachine_PRIVATE alloc] 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;
Expand Down Expand Up @@ -606,16 +609,16 @@ - (void)switchWorkspaceWithOptions:(MParticleOptions *)options {
#pragma mark Application notifications
#if TARGET_OS_IOS == 1
- (NSData *)pushNotificationToken {
if (![MPStateMachine_PRIVATE isAppExtension]) {
return [MPNotificationController_PRIVATE deviceToken];
if (![self.appEnvironmentProvider isAppExtension]) {
return [self.notificationController deviceToken];
} else {
return nil;
}
}

- (void)setPushNotificationToken:(NSData *)pushNotificationToken {
if (![MPStateMachine_PRIVATE isAppExtension]) {
[MPNotificationController_PRIVATE setDeviceToken:pushNotificationToken];
if (![self.appEnvironmentProvider isAppExtension]) {
[self.notificationController setDeviceToken:pushNotificationToken];
}
}

Expand All @@ -624,7 +627,7 @@ - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo {
return;
}

if (![MPStateMachine_PRIVATE isAppExtension]) {
if (![self.appEnvironmentProvider isAppExtension]) {
[[MParticle sharedInstance].appNotificationHandler didReceiveRemoteNotification:userInfo];
}
}
Expand All @@ -634,7 +637,7 @@ - (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
return;
}

if (![MPStateMachine_PRIVATE isAppExtension]) {
if (![self.appEnvironmentProvider isAppExtension]) {
[[MParticle sharedInstance].appNotificationHandler didFailToRegisterForRemoteNotificationsWithError:error];
}
}
Expand All @@ -644,7 +647,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
return;
}

if (![MPStateMachine_PRIVATE isAppExtension]) {
if (![self.appEnvironmentProvider isAppExtension]) {
[[MParticle sharedInstance].appNotificationHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
}
Expand All @@ -654,7 +657,7 @@ - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:
return;
}

if (![MPStateMachine_PRIVATE isAppExtension]) {
if (![self.appEnvironmentProvider isAppExtension]) {
[[MParticle sharedInstance].appNotificationHandler handleActionWithIdentifier:identifier forRemoteNotification:userInfo];
}
}
Expand All @@ -664,7 +667,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];
}
}
Expand Down
Loading