Skip to content

Commit f5fe3e0

Browse files
authored
Merge pull request #898 from BranchMetrics/GH-892-validator-error
GH-892 Fix Validator Error
2 parents 08918b2 + f9781c9 commit f5fe3e0

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

Branch-SDK/Branch-SDK/Branch+Validator.m

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "BNCSystemObserver.h"
1111
#import "BranchConstants.h"
1212
#import "BNCApplication.h"
13+
#import "BNCEncodingUtils.h"
1314

1415
void BNCForceBranchValidatorCategoryToLoad(void) {
1516
// Empty body but forces loader to load the category.
@@ -55,40 +56,49 @@ - (void) startValidation {
5556
}
5657

5758
- (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response {
58-
NSString *passString = @"PASS";
59-
NSString *errorString = @"ERROR";
59+
NSString*passString = @"PASS";
60+
NSString*errorString = @"ERROR";
6061

62+
// Decode the server message:
63+
NSString*serverUriScheme = BNCStringFromWireFormat(response.data[@"ios_uri_scheme"]) ?: @"";
64+
NSString*serverBundleID = BNCStringFromWireFormat(response.data[@"ios_bundle_id"]) ?: @"";
65+
NSString*serverTeamID = BNCStringFromWireFormat(response.data[@"ios_team_id"]) ?: @"";
66+
67+
// Verify:
6168
NSLog(@"** Initiating Branch integration verification **");
6269
NSLog(@"-------------------------------------------------");
6370

6471
NSLog(@"------ Checking for URI scheme correctness ------");
65-
NSString *serverUriScheme = response.data[@"ios_uri_scheme"];
6672
NSString *clientUriScheme = [NSString stringWithFormat:@"%@%@", [BNCSystemObserver getDefaultUriScheme], @"://"];
6773
NSString *uriScheme = [serverUriScheme isEqualToString:clientUriScheme] ? passString : errorString;
68-
NSString *uriSchemeMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", uriScheme, serverUriScheme, clientUriScheme];
74+
NSString *uriSchemeMessage =
75+
[NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'",
76+
uriScheme, serverUriScheme, clientUriScheme];
6977
NSLog(@"%@",uriSchemeMessage);
7078
NSLog(@"-------------------------------------------------");
7179

7280
NSLog(@"-- Checking for bundle identifier correctness ---");
73-
NSString *serverBundleIdentifier = [response.data[@"ios_bundle_id"] isKindOfClass:NSString.class] ? response.data[@"ios_bundle_id"] : @"";
74-
NSString *clientBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
75-
NSString *bundleIdentifier = [serverBundleIdentifier isEqualToString:clientBundleIdentifier] ? passString : errorString;
76-
NSString *bundleIdentifierMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", bundleIdentifier, serverBundleIdentifier, clientBundleIdentifier];
81+
NSString *clientBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier] ?: @"";
82+
NSString *bundleIdentifier = [serverBundleID isEqualToString:clientBundleIdentifier] ? passString : errorString;
83+
NSString *bundleIdentifierMessage =
84+
[NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'",
85+
bundleIdentifier, serverBundleID, clientBundleIdentifier];
7786
NSLog(@"%@",bundleIdentifierMessage);
7887
NSLog(@"-------------------------------------------------");
7988

8089
NSLog(@"----- Checking for iOS Team ID correctness ------");
81-
NSString *serverTeamId = response.data[@"ios_team_id"];
82-
NSString *clientTeamId = [BNCApplication currentApplication].teamID;
83-
NSString *teamID = [serverTeamId isEqualToString:clientTeamId] ? passString : errorString;
84-
NSString *teamIDMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", teamID, serverTeamId, clientTeamId];
90+
NSString *clientTeamId = [BNCApplication currentApplication].teamID ?: @"";
91+
NSString *teamID = [serverTeamID isEqualToString:clientTeamId] ? passString : errorString;
92+
NSString *teamIDMessage =
93+
[NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'",
94+
teamID, serverTeamID, clientTeamId];
8595
NSLog(@"%@",teamIDMessage);
8696
NSLog(@"-------------------------------------------------");
8797

8898
if ([teamID isEqualToString:errorString] ||
8999
[bundleIdentifier isEqualToString:errorString] ||
90100
[uriScheme isEqualToString:errorString]) {
91-
NSLog(@"%@: server side '%@' compared to client side '%@'.", errorString, serverTeamId, clientTeamId);
101+
NSLog(@"%@: server side '%@' compared to client side '%@'.", errorString, serverTeamID, clientTeamId);
92102
NSLog(@"To fix your Dashboard settings head over to https://branch.app.link/link-settings-page");
93103
NSLog(@"If you see a null value on the client side, please temporarily add the following key-value pair to your plist: \n\t<key>AppIdentifierPrefix</key><string>$(AppIdentifierPrefix)</string>\n-> then re-run this test.");
94104
NSLog(@"-------------------------------------------------");
@@ -113,22 +123,22 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response {
113123
kFailMark, serverUriScheme];
114124
}
115125

116-
if ([serverBundleIdentifier isEqualToString:clientBundleIdentifier]) {
126+
if ([serverBundleID isEqualToString:clientBundleIdentifier]) {
117127
alertString = [alertString stringByAppendingFormat:@"%@App Bundle ID matches:\n\t'%@'\n",
118-
kPassMark, serverBundleIdentifier];
128+
kPassMark, serverBundleID];
119129
} else {
120130
testsFailed = YES;
121131
alertString = [alertString stringByAppendingFormat:@"%@App Bundle ID mismatch:\n\t'%@'\n",
122-
kFailMark, serverBundleIdentifier];
132+
kFailMark, serverBundleID];
123133
}
124134

125-
if ([serverTeamId isEqualToString:clientTeamId]) {
135+
if ([serverTeamID isEqualToString:clientTeamId]) {
126136
alertString = [alertString stringByAppendingFormat:@"%@Team ID matches:\n\t'%@'\n",
127-
kPassMark, serverTeamId];
137+
kPassMark, serverTeamID];
128138
} else {
129139
testsFailed = YES;
130140
alertString = [alertString stringByAppendingFormat:@"%@Team ID mismatch:\n\t'%@'\n",
131-
kFailMark, serverTeamId];
141+
kFailMark, serverTeamID];
132142
}
133143

134144
if (testsFailed) {

0 commit comments

Comments
 (0)