Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions UnitTests/MParticle+PrivateMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "MPDataPlanFilter.h"
#import "AppEnvironmentProvider.h"
#import "MPAppNotificationHandler.h"
#import "SceneDelegateHandler.h"

@interface MParticle (Tests)
- (void)setOptOutCompletion:(MPExecStatus)execStatus optOut:(BOOL)optOut;
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/Mocks/SceneDelegateHandlerMock.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest
import mParticle_Apple_SDK_NoLocation

class OpenURLHandlerProtocolMock: OpenURLHandlerProtocol {
class OpenURLHandlerProtocolMock: NSObject, OpenURLHandlerProtocol {

var openURLWithOptionsCalled = false
var openURLWithOptionsURLParam: URL?
Expand All @@ -18,7 +18,7 @@ class OpenURLHandlerProtocolMock: OpenURLHandlerProtocol {
var continueUserActivityRestorationHandlerParam: (([UIUserActivityRestoring]?) -> Void)?
var continueUserActivityReturnValue: Bool = false

func continueUserActivity(
func `continue`(
_ userActivity: NSUserActivity,
restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void
) -> Bool {
Expand Down
22 changes: 12 additions & 10 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
351308432E6B28F5002A3AD6 /* Executor.h in Headers */ = {isa = PBXBuildFile; fileRef = 3513083F2E6B28F5002A3AD6 /* Executor.h */; };
351308442E6B28F5002A3AD6 /* Executor.m in Sources */ = {isa = PBXBuildFile; fileRef = 351308402E6B28F5002A3AD6 /* Executor.m */; };
351779502E706BF8004BF05E /* ExecutorMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3517794C2E706BE4004BF05E /* ExecutorMock.swift */; };
351F6FC82EDF7B2A00E527A7 /* SceneDelegateHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351F6FC62EDF7B2100E527A7 /* SceneDelegateHandler.swift */; };
35329FE92E54C38C009AC4FD /* MPNetworkOptions+MParticlePrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 35329FE82E54C38C009AC4FD /* MPNetworkOptions+MParticlePrivate.m */; };
35329FEC2E54C483009AC4FD /* MPNetworkOptions+MParticlePrivateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35329FEB2E54C480009AC4FD /* MPNetworkOptions+MParticlePrivateTests.swift */; };
35329FF02E54CA49009AC4FD /* MParticleOptions+MParticlePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 35329FEE2E54CA49009AC4FD /* MParticleOptions+MParticlePrivate.h */; };
Expand Down Expand Up @@ -237,6 +236,9 @@
53A79DBA29CE23F700E7489F /* MPUploadBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B1229CDFB1F00E7489F /* MPUploadBuilder.m */; };
53A79DBC29CE23F700E7489F /* MPBaseProjection.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79B5329CDFB1F00E7489F /* MPBaseProjection.m */; };
53A79DBF29CE23F700E7489F /* MPIdentityApiManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 53A79AA229CDFB1E00E7489F /* MPIdentityApiManager.m */; };
7213DE7F2F2D85980007A619 /* SceneDelegateHandlerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7213DE7E2F2D85980007A619 /* SceneDelegateHandlerMock.swift */; };
7213DE812F30F0DF0007A619 /* SceneDelegateHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 7213DE802F30F0DF0007A619 /* SceneDelegateHandler.h */; };
7213DE832F30F0EC0007A619 /* SceneDelegateHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7213DE822F30F0EC0007A619 /* SceneDelegateHandler.m */; };
7231B80E2EB3C4AC001565E5 /* MPKitMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7231B80C2EB3C4AC001565E5 /* MPKitMock.swift */; };
7231B81A2EB94DCD001565E5 /* MParticleTestBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7231B8192EB94DCD001565E5 /* MParticleTestBase.swift */; };
7231B81D2EB94EAA001565E5 /* MParticleConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7231B81C2EB94EAA001565E5 /* MParticleConfigurationTests.swift */; };
Expand Down Expand Up @@ -269,7 +271,6 @@
7E0387822DB913D2003B7D5E /* MPRokt.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E0387802DB913D2003B7D5E /* MPRokt.m */; };
7E15B2062D94617900C1FF3E /* MPRoktTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E15B2052D94617900C1FF3E /* MPRoktTests.m */; };
7E573D2A2ECB65D90087185D /* MParticleSceneDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E573D292ECB65D90087185D /* MParticleSceneDelegateTests.swift */; };
7E87E0C22EE093E100A18E3A /* SceneDelegateHandlerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E87E0BE2EE093E100A18E3A /* SceneDelegateHandlerMock.swift */; };
B3D778622E02F55F00D887A4 /* MPRoktEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B31360F72E012760000DFBC9 /* MPRoktEvent.swift */; };
D33C8B342B8510C20012EDFD /* MPAudience.h in Headers */ = {isa = PBXBuildFile; fileRef = D33C8B312B8510C20012EDFD /* MPAudience.h */; settings = {ATTRIBUTES = (Public, ); }; };
D33C8B362B8510C20012EDFD /* MPAudience.m in Sources */ = {isa = PBXBuildFile; fileRef = D33C8B322B8510C20012EDFD /* MPAudience.m */; };
Expand Down Expand Up @@ -325,7 +326,6 @@
3513083F2E6B28F5002A3AD6 /* Executor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Executor.h; sourceTree = "<group>"; };
351308402E6B28F5002A3AD6 /* Executor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Executor.m; sourceTree = "<group>"; };
3517794C2E706BE4004BF05E /* ExecutorMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExecutorMock.swift; sourceTree = "<group>"; };
351F6FC62EDF7B2100E527A7 /* SceneDelegateHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegateHandler.swift; sourceTree = "<group>"; };
35329FE82E54C38C009AC4FD /* MPNetworkOptions+MParticlePrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MPNetworkOptions+MParticlePrivate.m"; sourceTree = "<group>"; };
35329FEB2E54C480009AC4FD /* MPNetworkOptions+MParticlePrivateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MPNetworkOptions+MParticlePrivateTests.swift"; sourceTree = "<group>"; };
35329FEE2E54CA49009AC4FD /* MParticleOptions+MParticlePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MParticleOptions+MParticlePrivate.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -498,7 +498,6 @@
53A79C4329CDFB4800E7489F /* MPProduct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPProduct.h; sourceTree = "<group>"; };
53A79C4429CDFB4800E7489F /* MPTransactionAttributes+Dictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPTransactionAttributes+Dictionary.h"; sourceTree = "<group>"; };
53A79C6829CE019E00E7489F /* MPPersistenceControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPersistenceControllerTests.m; sourceTree = "<group>"; };
53A79C6929CE019E00E7489F /* MParticleWebViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MParticleWebViewTests.m; sourceTree = "<group>"; };
53A79C6A29CE019E00E7489F /* MPKitAppsFlyerTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKitAppsFlyerTest.h; sourceTree = "<group>"; };
53A79C6B29CE019E00E7489F /* MPKitTestClassSideloaded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKitTestClassSideloaded.m; sourceTree = "<group>"; };
53A79C6C29CE019E00E7489F /* MPCommerceEventTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPCommerceEventTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -564,6 +563,9 @@
53A79CFE29CE12AB00E7489F /* mParticle-Apple-SDK.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = "mParticle-Apple-SDK.modulemap"; path = "Framework/mParticle-Apple-SDK.modulemap"; sourceTree = "<group>"; };
53A79CFF29CE23D600E7489F /* mParticle-Apple-SDK-NoLocation.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = "mParticle-Apple-SDK-NoLocation.modulemap"; path = "Framework/mParticle-Apple-SDK-NoLocation.modulemap"; sourceTree = "<group>"; };
53A79DC629CE23F700E7489F /* mParticle_Apple_SDK_NoLocation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_Apple_SDK_NoLocation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7213DE7E2F2D85980007A619 /* SceneDelegateHandlerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegateHandlerMock.swift; sourceTree = "<group>"; };
7213DE802F30F0DF0007A619 /* SceneDelegateHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegateHandler.h; sourceTree = "<group>"; };
7213DE822F30F0EC0007A619 /* SceneDelegateHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegateHandler.m; sourceTree = "<group>"; };
7231B80C2EB3C4AC001565E5 /* MPKitMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPKitMock.swift; sourceTree = "<group>"; };
7231B8192EB94DCD001565E5 /* MParticleTestBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MParticleTestBase.swift; sourceTree = "<group>"; };
7231B81C2EB94EAA001565E5 /* MParticleConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MParticleConfigurationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -596,7 +598,6 @@
7E0387802DB913D2003B7D5E /* MPRokt.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPRokt.m; sourceTree = "<group>"; };
7E15B2052D94617900C1FF3E /* MPRoktTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPRoktTests.m; sourceTree = "<group>"; };
7E573D292ECB65D90087185D /* MParticleSceneDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MParticleSceneDelegateTests.swift; sourceTree = "<group>"; };
7E87E0BE2EE093E100A18E3A /* SceneDelegateHandlerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SceneDelegateHandlerMock.swift; path = UnitTests/Mocks/SceneDelegateHandlerMock.swift; sourceTree = "<group>"; };
B31360F72E012760000DFBC9 /* MPRoktEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPRoktEvent.swift; sourceTree = "<group>"; };
D33C8B312B8510C20012EDFD /* MPAudience.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPAudience.h; sourceTree = "<group>"; };
D33C8B322B8510C20012EDFD /* MPAudience.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPAudience.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -701,6 +702,7 @@
356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */,
727801DD2EB0FE8400BDAD98 /* MPNotificationControllerMock.swift */,
727801E02EB0FECA00BDAD98 /* AppEnvironmentProviderMock.swift */,
7213DE7E2F2D85980007A619 /* SceneDelegateHandlerMock.swift */,
727801E32EB1131B00BDAD98 /* MPAppNotificationHandlerMock.swift */,
7231B80C2EB3C4AC001565E5 /* MPKitMock.swift */,
);
Expand All @@ -710,7 +712,6 @@
53A79A6F29CCCD6400E7489F = {
isa = PBXGroup;
children = (
7E87E0BE2EE093E100A18E3A /* SceneDelegateHandlerMock.swift */,
D3BA75152B614E3D008C3C65 /* PrivacyInfo.xcprivacy */,
53A79CFE29CE12AB00E7489F /* mParticle-Apple-SDK.modulemap */,
53A79CFF29CE23D600E7489F /* mParticle-Apple-SDK-NoLocation.modulemap */,
Expand All @@ -736,7 +737,7 @@
53A79A7B29CCCD6400E7489F /* mParticle-Apple-SDK */ = {
isa = PBXGroup;
children = (
351F6FC62EDF7B2100E527A7 /* SceneDelegateHandler.swift */,
7213DE822F30F0EC0007A619 /* SceneDelegateHandler.m */,
3513083F2E6B28F5002A3AD6 /* Executor.h */,
729721752EAC2AD60045E55C /* AppEnvironmentProvider.h */,
729721782EAC2B750045E55C /* AppEnvironmentProvider.m */,
Expand Down Expand Up @@ -1039,6 +1040,7 @@
53A79ABB29CDFB1E00E7489F /* MPPersistenceController.h */,
7E03877F2DB913D2003B7D5E /* MPRokt.h */,
35C3DE6E2F2919B40077C0FD /* MPCCPAConsent.h */,
7213DE802F30F0DF0007A619 /* SceneDelegateHandler.h */,
);
path = Include;
sourceTree = "<group>";
Expand Down Expand Up @@ -1237,6 +1239,7 @@
53A79D2829CE23F700E7489F /* MPCustomModulePreference.h in Headers */,
53A79D2929CE23F700E7489F /* MPDataModelProtocol.h in Headers */,
53A79D2C29CE23F700E7489F /* MPIConstants.h in Headers */,
7213DE812F30F0DF0007A619 /* SceneDelegateHandler.h in Headers */,
359BAFF92E56330200A8A704 /* SettingsProvider.h in Headers */,
53A79D2E29CE23F700E7489F /* MPBackendController.h in Headers */,
7E0387812DB913D2003B7D5E /* MPRokt.h in Headers */,
Expand Down Expand Up @@ -1504,7 +1507,6 @@
534CD27829CE2CE1008452B3 /* MPPersistenceControllerTests.m in Sources */,
534CD27929CE2CE1008452B3 /* MPMessageTests.m in Sources */,
534CD27A29CE2CE1008452B3 /* MPDataPlanFilterTests.m in Sources */,
7E87E0C22EE093E100A18E3A /* SceneDelegateHandlerMock.swift in Sources */,
534CD27C29CE2CE1008452B3 /* MPIntegrationAttributesTest.m in Sources */,
356752932E60928B00DEEE23 /* MPStateMachineMock.swift in Sources */,
534CD27D29CE2CE1008452B3 /* MPDataModelTests.m in Sources */,
Expand All @@ -1521,6 +1523,7 @@
727801E42EB1131B00BDAD98 /* MPAppNotificationHandlerMock.swift in Sources */,
7231B83A2EB960C8001565E5 /* MParticleTimedEventTests.swift in Sources */,
7231B85E2EB96D88001565E5 /* MParticleBackendControllerDelegateTests.swift in Sources */,
7213DE7F2F2D85980007A619 /* SceneDelegateHandlerMock.swift in Sources */,
534CD28629CE2CE1008452B3 /* MPKitActivityTests.m in Sources */,
7231B83F2EB9627D001565E5 /* MParticleErrorTests.swift in Sources */,
534CD28729CE2CE1008452B3 /* MPKitTestClassSideloaded.m in Sources */,
Expand Down Expand Up @@ -1578,7 +1581,6 @@
53A79D6F29CE23F700E7489F /* mParticle.m in Sources */,
53A79D7029CE23F700E7489F /* MPProduct.m in Sources */,
35329FF32E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m in Sources */,
530D247F2CFF70B0000FE7E3 /* MPUserIdentityInstance.swift in Sources */,
53A79D7129CE23F700E7489F /* MPPersistenceController.m in Sources */,
351308442E6B28F5002A3AD6 /* Executor.m in Sources */,
53A79D7329CE23F700E7489F /* FilteredMParticleUser.m in Sources */,
Expand Down Expand Up @@ -1615,6 +1617,7 @@
53A79D9429CE23F700E7489F /* MPConnector.m in Sources */,
53A79D9529CE23F700E7489F /* MPBreadcrumb.m in Sources */,
53A79D9629CE23F700E7489F /* MPEnums.m in Sources */,
7213DE832F30F0EC0007A619 /* SceneDelegateHandler.m in Sources */,
53A79D9729CE23F700E7489F /* MPNetworkPerformance.m in Sources */,
53A79D9929CE23F700E7489F /* MPDataPlanFilter.m in Sources */,
53A79D9A29CE23F700E7489F /* MPSession.m in Sources */,
Expand Down Expand Up @@ -1646,7 +1649,6 @@
53A79DB129CE23F700E7489F /* MPTransactionAttributes.m in Sources */,
53A79DB329CE23F700E7489F /* MPCommerceEventInstruction.m in Sources */,
53A79DB429CE23F700E7489F /* MPDataModelAbstract.m in Sources */,
351F6FC82EDF7B2A00E527A7 /* SceneDelegateHandler.swift in Sources */,
53A79DB529CE23F700E7489F /* MPBackendController.m in Sources */,
53A79DB629CE23F700E7489F /* MPForwardQueueItem.m in Sources */,
53A79DB729CE23F700E7489F /* MPEventProjection.m in Sources */,
Expand Down
25 changes: 25 additions & 0 deletions mParticle-Apple-SDK/Include/SceneDelegateHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>


NS_ASSUME_NONNULL_BEGIN

@protocol OpenURLHandlerProtocol <NSObject>
- (void)open:(NSURL *)url options:(nullable NSDictionary<NSString *, id> *)options;
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^_Nonnull)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler;
@end

@interface SceneDelegateHandler : NSObject

- (instancetype)initWithAppNotificationHandler:(id<OpenURLHandlerProtocol>)appNotificationHandler;
- (void)handleUserActivity:(NSUserActivity *)userActivity;

#if TARGET_OS_IOS == 1
- (void)handleWithUrlContext:(UIOpenURLContext *)urlContext API_AVAILABLE(ios(13.0));
#endif

@end

NS_ASSUME_NONNULL_END

56 changes: 56 additions & 0 deletions mParticle-Apple-SDK/SceneDelegateHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#import "SceneDelegateHandler.h"
#import "MPILogger.h"
#import "mParticle.h"

@interface SceneDelegateHandler ()
@property (nonatomic, strong) id<OpenURLHandlerProtocol> appNotificationHandler;
@end

@implementation SceneDelegateHandler

- (instancetype)initWithAppNotificationHandler:(id<OpenURLHandlerProtocol>)appNotificationHandler {
self = [super init];
if (self) {
_appNotificationHandler = appNotificationHandler;
}
return self;
}

#if TARGET_OS_IOS
- (void)handleWithUrlContext:(UIOpenURLContext *)urlContext API_AVAILABLE(ios(13.0)) {

MPILogDebug(@"Opening URLContext URL: %@", urlContext.URL);
MPILogDebug(@"Source: %@", urlContext.options.sourceApplication ?: @"unknown");
MPILogDebug(@"Annotation: %@", urlContext.options.annotation);

if (@available(iOS 14.5, *)) {
MPILogDebug(@"Event Attribution: %@", urlContext.options.eventAttribution);
}

MPILogDebug(@"Open in place: %@", urlContext.options.openInPlace ? @"True" : @"False");

NSMutableDictionary *options = [NSMutableDictionary dictionary];
if (urlContext.options.sourceApplication) {
options[@"UIApplicationOpenURLOptionsSourceApplicationKey"] = urlContext.options.sourceApplication;
}

[self.appNotificationHandler open:urlContext.URL options:options];
}
#endif

- (void)handleUserActivity:(NSUserActivity *)userActivity {
MPILogDebug(@"User Activity Received");
MPILogDebug(@"User Activity Type: %@", userActivity.activityType);
MPILogDebug(@"User Activity Title: %@", userActivity.title ?: @"");
MPILogDebug(@"User Activity User Info: %@", userActivity.userInfo ?: @{});

if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
MPILogDebug(@"Opening UserActivity URL: %@", userActivity.webpageURL.absoluteString ?: @"");
}

(void)[self.appNotificationHandler continueUserActivity:userActivity
restorationHandler:^(__unused NSArray<id<UIUserActivityRestoring>> * _Nullable restorableObjects) {
}];
}

@end
Loading
Loading