diff --git a/.gitignore b/.gitignore index 84299e3..f328143 100644 --- a/.gitignore +++ b/.gitignore @@ -46,9 +46,9 @@ Pods/ # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. -Carthage/Checkouts +**/Carthage/Checkouts -Carthage/Build +**/Carthage/Build # fastlane # diff --git a/Cartfile b/Cartfile new file mode 100644 index 0000000..41790c3 --- /dev/null +++ b/Cartfile @@ -0,0 +1,2 @@ +github "BranchMetrics/iOS-Deferred-Deep-Linking-SDK" == 0.11.18 +github "mparticle/mparticle-apple-sdk" ~> 6.0.0 diff --git a/README.md b/README.md index b500dea..f73d81e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,23 @@ -# mparticle-apple-integration-branchmetrics +# mParticle Apple Kit Library + +A kit is an extension to the core [mParticle Apple SDK](https://github.com/mParticle/mparticle-apple-sdk). A kit works as a bridge between the mParticle SDK and a partner SDK. It abstracts the implementation complexity, simplifying the implementation for developers. + +A kit takes care of initializing and forwarding information depending on what you've configured in [your app's dashboard](https://app.mparticle.com), so you just have to decide which kits you may use prior to submission to the App Store. You can easily include all of the kits, none of the kits, or individual kits – the choice is yours. + +[![CocoaPods compatible](http://img.shields.io/badge/CocoaPods-compatible-brightgreen.png)](https://cocoapods.org/?q=mparticle) +[![Carthage compatible](http://img.shields.io/badge/Carthage-compatible-brightgreen.png)](https://github.com/Carthage/Carthage) + + +## Installation + +Please refer to installation instructions in the core mParticle Apple SDK [README](https://github.com/mParticle/mparticle-apple-sdk#get-the-sdk), or check out our [SDK Documentation](http://docs.mparticle.com/#sdk-documentation) site to learn more. + + +## Support + +Questions? Give us a shout at -BranchMetrics Apple integration for mParticle ## License -[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) +This mParticle Apple Kit is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). See the LICENSE file for more info. diff --git a/mParticle-BranchMetrics.podspec b/mParticle-BranchMetrics.podspec index 1f5058f..87567eb 100644 --- a/mParticle-BranchMetrics.podspec +++ b/mParticle-BranchMetrics.podspec @@ -1,20 +1,20 @@ Pod::Spec.new do |s| - s.name = "mParticle-BranchMetrics" - s.version = "6.0.0" - s.summary = "BranchMetrics integration for mParticle" + s.name = "mParticle-BranchMetrics" + s.version = "6.0.0" + s.summary = "BranchMetrics integration for mParticle" - s.description = <<-DESC + s.description = <<-DESC This is the BranchMetrics integration for mParticle. DESC - s.homepage = "https://www.mparticle.com" - s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } - s.author = { "mParticle" => "support@mparticle.com" } - s.source = { :git => "https://github.com/mparticle-integrations/mparticle-apple-integration-branchmetrics.git", :tag => s.version.to_s } - s.social_media_url = "https://twitter.com/mparticles" + s.homepage = "https://www.mparticle.com" + s.license = { :type => 'Apache 2.0', :file => 'LICENSE' } + s.author = { "mParticle" => "support@mparticle.com" } + s.source = { :git => "https://github.com/mparticle-integrations/mparticle-apple-integration-branchmetrics.git", :tag => s.version.to_s } + s.social_media_url = "https://twitter.com/mparticles" - s.source_files = 'mParticle-BranchMetrics/*.{h,m,mm}' - - s.dependency 'mParticle-Apple-SDK', '6.0.0' - s.dependency 'Branch', '0.11.18' + s.ios.deployment_target = "7.0" + s.ios.source_files = 'mParticle-BranchMetrics/*.{h,m,mm}' + s.ios.dependency 'mParticle-Apple-SDK/mParticle', '~> 6.0' + s.ios.dependency 'Branch', '0.11.18' end diff --git a/mParticle-BranchMetrics.xcodeproj/project.pbxproj b/mParticle-BranchMetrics.xcodeproj/project.pbxproj new file mode 100644 index 0000000..262baef --- /dev/null +++ b/mParticle-BranchMetrics.xcodeproj/project.pbxproj @@ -0,0 +1,313 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + DB61C5EC1CBEBE2900FEEB1D /* BranchSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB9401771CB70C58007ABB18 /* BranchSDK.framework */; }; + DB7E05A61CB819D300967FDF /* MPKitBranchMetrics.h in Headers */ = {isa = PBXBuildFile; fileRef = DB7E05A41CB819D300967FDF /* MPKitBranchMetrics.h */; }; + DB7E05A71CB819D300967FDF /* MPKitBranchMetrics.m in Sources */ = {isa = PBXBuildFile; fileRef = DB7E05A51CB819D300967FDF /* MPKitBranchMetrics.m */; }; + DB9401701CB703F2007ABB18 /* mParticle_BranchMetrics.h in Headers */ = {isa = PBXBuildFile; fileRef = DB94016F1CB703F2007ABB18 /* mParticle_BranchMetrics.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DB94017A1CB70C58007ABB18 /* mParticle_Apple_SDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB9401781CB70C58007ABB18 /* mParticle_Apple_SDK.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + DB7E05A41CB819D300967FDF /* MPKitBranchMetrics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPKitBranchMetrics.h; sourceTree = ""; }; + DB7E05A51CB819D300967FDF /* MPKitBranchMetrics.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPKitBranchMetrics.m; sourceTree = ""; }; + DB94016C1CB703F2007ABB18 /* mParticle_BranchMetrics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = mParticle_BranchMetrics.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DB94016F1CB703F2007ABB18 /* mParticle_BranchMetrics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mParticle_BranchMetrics.h; sourceTree = ""; }; + DB9401711CB703F2007ABB18 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DB9401771CB70C58007ABB18 /* BranchSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BranchSDK.framework; path = Carthage/Build/iOS/BranchSDK.framework; sourceTree = ""; }; + DB9401781CB70C58007ABB18 /* mParticle_Apple_SDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = mParticle_Apple_SDK.framework; path = Carthage/Build/iOS/mParticle_Apple_SDK.framework; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DB9401681CB703F2007ABB18 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + DB94017A1CB70C58007ABB18 /* mParticle_Apple_SDK.framework in Frameworks */, + DB61C5EC1CBEBE2900FEEB1D /* BranchSDK.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DB9401621CB703F2007ABB18 = { + isa = PBXGroup; + children = ( + DB9401771CB70C58007ABB18 /* BranchSDK.framework */, + DB9401781CB70C58007ABB18 /* mParticle_Apple_SDK.framework */, + DB94016E1CB703F2007ABB18 /* mParticle-BranchMetrics */, + DB94016D1CB703F2007ABB18 /* Products */, + ); + sourceTree = ""; + }; + DB94016D1CB703F2007ABB18 /* Products */ = { + isa = PBXGroup; + children = ( + DB94016C1CB703F2007ABB18 /* mParticle_BranchMetrics.framework */, + ); + name = Products; + sourceTree = ""; + }; + DB94016E1CB703F2007ABB18 /* mParticle-BranchMetrics */ = { + isa = PBXGroup; + children = ( + DB7E05A41CB819D300967FDF /* MPKitBranchMetrics.h */, + DB7E05A51CB819D300967FDF /* MPKitBranchMetrics.m */, + DB94016F1CB703F2007ABB18 /* mParticle_BranchMetrics.h */, + DB9401711CB703F2007ABB18 /* Info.plist */, + ); + path = "mParticle-BranchMetrics"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + DB9401691CB703F2007ABB18 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + DB9401701CB703F2007ABB18 /* mParticle_BranchMetrics.h in Headers */, + DB7E05A61CB819D300967FDF /* MPKitBranchMetrics.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + DB94016B1CB703F2007ABB18 /* mParticle-BranchMetrics */ = { + isa = PBXNativeTarget; + buildConfigurationList = DB9401741CB703F2007ABB18 /* Build configuration list for PBXNativeTarget "mParticle-BranchMetrics" */; + buildPhases = ( + DB9401671CB703F2007ABB18 /* Sources */, + DB9401681CB703F2007ABB18 /* Frameworks */, + DB9401691CB703F2007ABB18 /* Headers */, + DB94016A1CB703F2007ABB18 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "mParticle-BranchMetrics"; + productName = "mParticle-BranchMetrics"; + productReference = DB94016C1CB703F2007ABB18 /* mParticle_BranchMetrics.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DB9401631CB703F2007ABB18 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0730; + ORGANIZATIONNAME = mParticle; + TargetAttributes = { + DB94016B1CB703F2007ABB18 = { + CreatedOnToolsVersion = 7.3; + DevelopmentTeam = Q948K5LXGZ; + }; + }; + }; + buildConfigurationList = DB9401661CB703F2007ABB18 /* Build configuration list for PBXProject "mParticle-BranchMetrics" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = DB9401621CB703F2007ABB18; + productRefGroup = DB94016D1CB703F2007ABB18 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DB94016B1CB703F2007ABB18 /* mParticle-BranchMetrics */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DB94016A1CB703F2007ABB18 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DB9401671CB703F2007ABB18 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DB7E05A71CB819D300967FDF /* MPKitBranchMetrics.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + DB9401721CB703F2007ABB18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + DB9401731CB703F2007ABB18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + DB9401751CB703F2007ABB18 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "mParticle-BranchMetrics/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-BranchMetrics"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + DB9401761CB703F2007ABB18 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "mParticle-BranchMetrics/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mparticle.mParticle-BranchMetrics"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DB9401661CB703F2007ABB18 /* Build configuration list for PBXProject "mParticle-BranchMetrics" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB9401721CB703F2007ABB18 /* Debug */, + DB9401731CB703F2007ABB18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DB9401741CB703F2007ABB18 /* Build configuration list for PBXNativeTarget "mParticle-BranchMetrics" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB9401751CB703F2007ABB18 /* Debug */, + DB9401761CB703F2007ABB18 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = DB9401631CB703F2007ABB18 /* Project object */; +} diff --git a/mParticle-BranchMetrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/mParticle-BranchMetrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..938129c --- /dev/null +++ b/mParticle-BranchMetrics.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/mParticle-BranchMetrics.xcodeproj/xcshareddata/xcschemes/mParticle-BranchMetrics.xcscheme b/mParticle-BranchMetrics.xcodeproj/xcshareddata/xcschemes/mParticle-BranchMetrics.xcscheme new file mode 100644 index 0000000..314140e --- /dev/null +++ b/mParticle-BranchMetrics.xcodeproj/xcshareddata/xcschemes/mParticle-BranchMetrics.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mParticle-BranchMetrics/Info.plist b/mParticle-BranchMetrics/Info.plist new file mode 100644 index 0000000..d3de8ee --- /dev/null +++ b/mParticle-BranchMetrics/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/mParticle-BranchMetrics/MPKitBranchMetrics.h b/mParticle-BranchMetrics/MPKitBranchMetrics.h index 92d836e..7ca10c0 100644 --- a/mParticle-BranchMetrics/MPKitBranchMetrics.h +++ b/mParticle-BranchMetrics/MPKitBranchMetrics.h @@ -17,8 +17,11 @@ // #import -#import "MPKitExecStatus.h" -#import "MPKitProtocol.h" +#if defined NO_USE_FRAMEWORKS +#import +#else +@import mParticle_Apple_SDK; +#endif @interface MPKitBranchMetrics : NSObject diff --git a/mParticle-BranchMetrics/MPKitBranchMetrics.m b/mParticle-BranchMetrics/MPKitBranchMetrics.m index a197938..1fd0d8c 100644 --- a/mParticle-BranchMetrics/MPKitBranchMetrics.m +++ b/mParticle-BranchMetrics/MPKitBranchMetrics.m @@ -17,10 +17,11 @@ // #import "MPKitBranchMetrics.h" -#import "MPEvent.h" -#import "mParticle.h" -#import "MPKitRegister.h" -#import "Branch.h" +#ifdef COCOAPODS + #import +#else + #import +#endif NSString *const ekBMAppKey = @"branchKey"; NSString *const ekBMAForwardScreenViews = @"forwardScreenViews"; @@ -28,6 +29,11 @@ @interface MPKitBranchMetrics() { Branch *branchInstance; BOOL forwardScreenViews; + NSDictionary *temporaryParams; + NSError *temporaryError; + BOOL isTemporaryInfoValid; + BOOL isBranchRequestPending; + void (^completionHandlerCopy)(NSDictionary *linkInfo, NSError *error); } @end @@ -55,6 +61,8 @@ - (instancetype)initWithConfiguration:(NSDictionary *)configuration startImmedia forwardScreenViews = [configuration[ekBMAForwardScreenViews] boolValue]; _configuration = configuration; _started = startImmediately; + isTemporaryInfoValid = NO; + isBranchRequestPending = NO; if (startImmediately) { [self start]; @@ -75,8 +83,21 @@ - (void)start { branchInstance = [Branch getInstance:branchKey]; _started = YES; + isBranchRequestPending = YES; [branchInstance initSessionWithLaunchOptions:self.launchOptions isReferrable:YES andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ + isBranchRequestPending = NO; + + if (completionHandlerCopy) { + completionHandlerCopy(params, error); + completionHandlerCopy = nil; + } + else { + isTemporaryInfoValid = YES; + temporaryParams = params; + temporaryError = error; + } + NSMutableDictionary *userInfo = [@{mParticleKitInstanceKey:[[self class] kitCode], @"branchKey":branchKey} mutableCopy]; @@ -176,4 +197,34 @@ - (MPKitExecStatus *)setUserIdentity:(NSString *)identityString identityType:(MP return execStatus; } +- (MPKitExecStatus *)checkForDeferredDeepLinkWithCompletionHandler:(void(^)(NSDictionary *linkInfo, NSError *error))completionHandler { + MPKitExecStatus *status; + + if (!temporaryError) { + status = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceBranchMetrics) returnCode:MPKitReturnCodeSuccess]; + } + else { + status = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceBranchMetrics) returnCode:MPKitReturnCodeFail]; + } + + // If we already have deep linking info stored in temporaries + if (isTemporaryInfoValid) { + // Trigger completion handler immediately, then clear state + completionHandler(temporaryParams, temporaryError); + isTemporaryInfoValid = NO; + temporaryParams = nil; + temporaryError = nil; + } + else if (isBranchRequestPending) { + // Otherwise if we're waiting for info from branch, save the completion handler + completionHandlerCopy = [completionHandler copy]; + } + else { + // If branch has already called back to us, we won't get any more info from them + // So this is a no-op + } + + return status; +} + @end diff --git a/mParticle-BranchMetrics/mParticle_BranchMetrics.h b/mParticle-BranchMetrics/mParticle_BranchMetrics.h new file mode 100644 index 0000000..8cc7219 --- /dev/null +++ b/mParticle-BranchMetrics/mParticle_BranchMetrics.h @@ -0,0 +1,19 @@ +// +// mParticle_BranchMetrics.h +// mParticle-BranchMetrics +// +// Created by Peter Jenkins on 4/7/16. +// Copyright © 2016 mParticle. All rights reserved. +// + +#import + +//! Project version number for mParticle-BranchMetrics. +FOUNDATION_EXPORT double mParticle_BranchMetricsVersionNumber; + +//! Project version string for mParticle-BranchMetrics. +FOUNDATION_EXPORT const unsigned char mParticle_BranchMetricsVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +#import \ No newline at end of file