Skip to content

Commit 5e31f14

Browse files
fix: Prevent Start When Configuration Not Set (#62)
1 parent 7cc4ce4 commit 5e31f14

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

mParticle-BranchMetrics/MPKitBranchMetrics.m

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ - (MPKitExecStatus*_Nonnull)didFinishLaunchingWithConfiguration:(NSDictionary *)
105105
}
106106
self.forwardScreenViews = [configuration[ekBMAForwardScreenViews] boolValue];
107107
[self updateIdentityType:configuration];
108+
[self start];
108109
return [self execStatus:MPKitReturnCodeSuccess];
109110
}
110111

@@ -154,54 +155,56 @@ - (id const)providerKitInstance {
154155
}
155156

156157
- (void)start {
157-
static dispatch_once_t branchMetricsPredicate = 0;
158-
dispatch_once(&branchMetricsPredicate, ^{
159-
NSString *branchKey = [self.configuration[ekBMAppKey] copy];
160-
self.branchInstance = [Branch getInstance:branchKey];
161-
162-
[self.branchInstance registerPluginName:@"mParticleKit" version:MPKitBranchMetricsVersionNumber];
163-
164-
// iOS 15 Branch NativeLink™ support
165-
// https://help.branch.io/developers-hub/docs/ios-advanced-features#nativelink-deferred-deep-linking
166-
#pragma clang diagnostic push
167-
#pragma clang diagnostic ignored "-Wundeclared-selector"
168-
if ([self.branchInstance respondsToSelector:@selector(checkPasteboardOnInstall)]) {
169-
[self.branchInstance performSelector:@selector(checkPasteboardOnInstall)];
170-
}
171-
#pragma clang diagnostic pop
172-
173-
[self.branchInstance initSessionWithLaunchOptions:self.launchOptions
174-
isReferrable:YES
175-
andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
176-
MPAttributionResult *attributionResult = [[MPAttributionResult alloc] init];
177-
if (error) {
178-
[self.kitApi onAttributionCompleteWithResult:attributionResult error:error];
179-
return;
180-
}
181-
attributionResult.linkInfo = params;
182-
[self->_kitApi onAttributionCompleteWithResult:attributionResult error:nil];
183-
}];
184-
185-
// mParticle isn't calling back with the URL on startup fast enough or in the right order, so handle it here:
186-
NSURL*URL = self.launchOptions[UIApplicationLaunchOptionsURLKey];
187-
if (URL) [self.branchInstance handleDeepLinkWithNewSession:URL];
188-
189-
dispatch_async(dispatch_get_main_queue(), ^{
190-
if (self.branchInstance) {
191-
self.started = YES;
158+
if (self.configuration[ekBMAppKey] != nil) {
159+
static dispatch_once_t branchMetricsPredicate = 0;
160+
dispatch_once(&branchMetricsPredicate, ^{
161+
NSString *branchKey = [self.configuration[ekBMAppKey] copy];
162+
self.branchInstance = [Branch getInstance:branchKey];
163+
164+
[self.branchInstance registerPluginName:@"mParticleKit" version:MPKitBranchMetricsVersionNumber];
165+
166+
// iOS 15 Branch NativeLink™ support
167+
// https://help.branch.io/developers-hub/docs/ios-advanced-features#nativelink-deferred-deep-linking
168+
#pragma clang diagnostic push
169+
#pragma clang diagnostic ignored "-Wundeclared-selector"
170+
if ([self.branchInstance respondsToSelector:@selector(checkPasteboardOnInstall)]) {
171+
[self.branchInstance performSelector:@selector(checkPasteboardOnInstall)];
192172
}
173+
#pragma clang diagnostic pop
193174

194-
NSMutableDictionary *userInfo = [@{
195-
mParticleKitInstanceKey: [[self class] kitCode],
196-
@"branchKey": (self.configuration[ekBMAppKey] != nil) ? self.configuration[ekBMAppKey] : @""
197-
} mutableCopy];
198-
199-
[[NSNotificationCenter defaultCenter]
200-
postNotificationName:mParticleKitDidBecomeActiveNotification
201-
object:nil
202-
userInfo:userInfo];
175+
[self.branchInstance initSessionWithLaunchOptions:self.launchOptions
176+
isReferrable:YES
177+
andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
178+
MPAttributionResult *attributionResult = [[MPAttributionResult alloc] init];
179+
if (error) {
180+
[self.kitApi onAttributionCompleteWithResult:attributionResult error:error];
181+
return;
182+
}
183+
attributionResult.linkInfo = params;
184+
[self->_kitApi onAttributionCompleteWithResult:attributionResult error:nil];
185+
}];
186+
187+
// mParticle isn't calling back with the URL on startup fast enough or in the right order, so handle it here:
188+
NSURL*URL = self.launchOptions[UIApplicationLaunchOptionsURLKey];
189+
if (URL) [self.branchInstance handleDeepLinkWithNewSession:URL];
190+
191+
dispatch_async(dispatch_get_main_queue(), ^{
192+
if (self.branchInstance) {
193+
self.started = YES;
194+
}
195+
196+
NSMutableDictionary *userInfo = [@{
197+
mParticleKitInstanceKey: [[self class] kitCode],
198+
@"branchKey": (self.configuration[ekBMAppKey] != nil) ? self.configuration[ekBMAppKey] : @""
199+
} mutableCopy];
200+
201+
[[NSNotificationCenter defaultCenter]
202+
postNotificationName:mParticleKitDidBecomeActiveNotification
203+
object:nil
204+
userInfo:userInfo];
205+
});
203206
});
204-
});
207+
}
205208
}
206209

207210
#pragma mark - MPKitInstanceProtocol Methods

0 commit comments

Comments
 (0)