Skip to content

Commit 2e1be32

Browse files
grimE-B-Smith
authored andcommitted
Remove any occurrences of -alternate links. (#810)
* Remove any occurances of -alterante links * Android parity. * Fixed the teamID issue. Fixed some verbage.
1 parent 0fa98f2 commit 2e1be32

File tree

10 files changed

+86
-17
lines changed

10 files changed

+86
-17
lines changed

Branch-SDK-Tests/Branch-SDK-Tests/BNCKeyChain.Test.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ - (void)testKeyChain {
8282
XCTAssertTrue([array isEqualToArray:@[ @"3xyz123" ]] && error == errSecSuccess);
8383
}
8484

85+
- (void) testSecurityAccessGroup {
86+
NSString *group = [BNCKeyChain securityAccessGroup];
87+
XCTAssert(group.length > 0);
88+
}
89+
8590
@end

Branch-SDK/Branch-SDK/BNCApplication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@
4949
/// Returns a dictionary of device / identity pairs.
5050
@property (atomic, readonly) NSDictionary<NSString*, NSString*>*_Nonnull deviceKeyIdentityValueDictionary;
5151

52+
/// The team identifier for the app.
53+
@property (atomic, readonly) NSString* teamID;
5254
@end

Branch-SDK/Branch-SDK/BNCApplication.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ + (BNCApplication*) createCurrentApplication {
4848
application->_firstInstallDate = [BNCApplication firstInstallDate];
4949
application->_currentInstallDate = [BNCApplication currentInstallDate];
5050

51+
NSString*group = [BNCKeyChain securityAccessGroup];
52+
if (group) {
53+
NSRange range = [group rangeOfString:@"."];
54+
if (range.location != NSNotFound) {
55+
application->_teamID = [[group substringToIndex:range.location] copy];
56+
}
57+
}
58+
5159
return application;
5260
}
5361

Branch-SDK/Branch-SDK/BNCKeyChain.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
error:(NSError*_Nullable __autoreleasing *_Nullable)error;
4040

4141
/**
42-
@brief Returns an array of all items found in the keychain.
42+
@brief Returns an array of all items found in the keychain for an app.
4343
4444
@param error If an error occurs, the error is returned in `error` if it is not `NULL`.
4545
@return Returns an array of the items stored in the keychain or `nil`.
@@ -58,4 +58,7 @@
5858
forService:(NSString*_Nonnull)service
5959
key:(NSString*_Nonnull)key
6060
cloudAccessGroup:(NSString*_Nullable)accessGroup;
61+
62+
/// The default security access group for the app.
63+
+ (NSString*_Nullable) securityAccessGroup;
6164
@end

Branch-SDK/Branch-SDK/BNCKeyChain.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,32 @@ + (NSError*) removeValuesForService:(NSString*)service key:(NSString*)key {
215215
return nil;
216216
}
217217

218+
+ (NSString*_Nullable) securityAccessGroup {
219+
// https://stackoverflow.com/questions/11726672/access-app-identifier-prefix-programmatically
220+
@synchronized(self) {
221+
static NSString*_securityAccessGroup = nil;
222+
if (_securityAccessGroup) return _securityAccessGroup;
223+
224+
NSDictionary* dictionary = @{
225+
(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
226+
(__bridge id)kSecReturnAttributes: (__bridge id)kCFBooleanTrue,
227+
(__bridge id)kSecAttrSynchronizable: (__bridge id)kSecAttrSynchronizableAny,
228+
(__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitOne
229+
};
230+
CFDictionaryRef resultDictionary = NULL;
231+
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef*)&resultDictionary);
232+
if (status == errSecItemNotFound) return nil;
233+
if (status != errSecSuccess) {
234+
BNCLogDebugSDK(@"Get securityAccessGroup returned(%ld): %@.",
235+
status, [self errorWithKey:nil OSStatus:status]);
236+
return nil;
237+
}
238+
NSString*group =
239+
[(__bridge NSDictionary *)resultDictionary objectForKey:(__bridge NSString *)kSecAttrAccessGroup];
240+
if (group.length > 0) _securityAccessGroup = [group copy];
241+
CFRelease(resultDictionary);
242+
return _securityAccessGroup;
243+
}
244+
}
245+
218246
@end

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "Branch+Validator.h"
1010
#import "BNCSystemObserver.h"
1111
#import "BranchConstants.h"
12+
#import "BNCApplication.h"
1213

1314
void BNCForceBranchValidatorCategoryToLoad(void) {
1415
// Empty body but forces loader to load the category.
@@ -38,14 +39,15 @@ - (void)validateSDKIntegrationCore {
3839

3940
- (void) startValidation {
4041
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
41-
NSString *endpoint = [BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS stringByAppendingPathComponent:preferenceHelper.lastRunBranchKey];
42+
NSString *endpoint =
43+
[BRANCH_REQUEST_ENDPOINT_APP_LINK_SETTINGS stringByAppendingPathComponent:preferenceHelper.lastRunBranchKey];
4244
[[[BNCServerInterface alloc] init]
4345
getRequest:nil
4446
url:[preferenceHelper getAPIURL:endpoint]
4547
key:nil
46-
callback:^(BNCServerResponse *response, NSError *error) {
48+
callback:^ (BNCServerResponse *response, NSError *error) {
4749
if (error) {
48-
[self showAlertWithTitle:@"" message:@""];
50+
[self showAlertWithTitle:@"Error" message:error.localizedDescription];
4951
} else {
5052
[self validateIntegrationWithServerResponse:response];
5153
}
@@ -59,25 +61,25 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response {
5961
NSLog(@"** Initiating Branch integration verification **");
6062
NSLog(@"-------------------------------------------------");
6163

62-
NSLog(@"------ checking for URI scheme correctness ------");
64+
NSLog(@"------ Checking for URI scheme correctness ------");
6365
NSString *serverUriScheme = response.data[@"ios_uri_scheme"];
6466
NSString *clientUriScheme = [NSString stringWithFormat:@"%@%@", [BNCSystemObserver getDefaultUriScheme], @"://"];
6567
NSString *uriScheme = [serverUriScheme isEqualToString:clientUriScheme] ? passString : errorString;
6668
NSString *uriSchemeMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", uriScheme, serverUriScheme, clientUriScheme];
6769
NSLog(@"%@",uriSchemeMessage);
6870
NSLog(@"-------------------------------------------------");
6971

70-
NSLog(@"-- checking for bundle identifier correctness ---");
72+
NSLog(@"-- Checking for bundle identifier correctness ---");
7173
NSString *serverBundleIdentifier = response.data[@"ios_bundle_id"];
7274
NSString *clientBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
7375
NSString *bundleIdentifier = [serverBundleIdentifier isEqualToString:clientBundleIdentifier] ? passString : errorString;
7476
NSString *bundleIdentifierMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", bundleIdentifier, serverBundleIdentifier, clientBundleIdentifier];
7577
NSLog(@"%@",bundleIdentifierMessage);
7678
NSLog(@"-------------------------------------------------");
7779

78-
NSLog(@"----- checking for iOS Team ID correctness ------");
80+
NSLog(@"----- Checking for iOS Team ID correctness ------");
7981
NSString *serverTeamId = response.data[@"ios_team_id"];
80-
NSString *clientTeamId = [BNCSystemObserver getTeamIdentifier];
82+
NSString *clientTeamId = [BNCApplication currentApplication].teamID;
8183
NSString *teamID = [serverTeamId isEqualToString:clientTeamId] ? passString : errorString;
8284
NSString *teamIDMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", teamID, serverTeamId, clientTeamId];
8385
NSLog(@"%@",teamIDMessage);
@@ -93,7 +95,7 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response {
9395
}
9496

9597
NSLog(@"-------------------------------------------------------------------------------------------------------------------");
96-
NSLog(@"-----To test your deeplink routing append ?validate=true to any branch link and click it on your mobile device-----");
98+
NSLog(@"-----To test your deeplink routing append ?bnc_validate=true to any branch link and click it on your mobile device-----");
9799
NSLog(@"-------------------------------------------------------------------------------------------------------------------");
98100

99101
BOOL testsFailed = NO;
@@ -170,14 +172,20 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response {
170172

171173
- (void) showNextStep {
172174
NSString *message =
173-
@"\nGreat! Comment out the 'validateSDKIntegration' line in your app.\n\n"
175+
@"\nGreat! Remove the 'validateSDKIntegration' line in your app.\n\n"
174176
"Next check your deep link routing.\n\n"
175-
"Append '?validate=true' to any of your app's Branch links and "
176-
"click it on your mobile device (not the Simulator!) to start the test.\n\n"
177+
"Append '?bnc_validate=true' to any of your app's Branch links and "
178+
"click on it on your mobile device (not the Simulator!) to start the test.\n\n"
177179
"For instance, to validate a link like:\n"
178180
"https://<yourapp>.app.link/NdJ6nFzRbK\n\n"
179181
"click on:\n"
180-
"https://<yourapp>.app.link/NdJ6nFzRbK?validate=true";
182+
"https://<yourapp>.app.link/NdJ6nFzRbK?bnc_validate=true";
183+
NSLog(
184+
@"\n----------------------------------------------------------------------------"
185+
"\nBranch Integration Next Steps\n"
186+
"\n"
187+
"%@"
188+
"\n----------------------------------------------------------------------------", message);
181189
[self showAlertWithTitle:@"Next Step" message:message];
182190
}
183191

@@ -283,6 +291,7 @@ + (NSString *) returnNonUniversalLink:(NSString *) referringLink {
283291
referringLink = [referringLink stringByAppendingString:@"/e/"];
284292
}
285293
}
294+
referringLink = [referringLink stringByReplacingOccurrencesOfString:@"-alternate" withString:@""];
286295
return referringLink;
287296
}
288297

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ - (void)handleInitSuccess {
21972197
if ([latestReferringParams[@"_branch_validate"] isEqualToString:@"060514"]) {
21982198
[self validateDeeplinkRouting:latestReferringParams];
21992199
}
2200-
else if (([latestReferringParams[@"validate"] isEqualToString:@"true"])) {
2200+
else if (([latestReferringParams[@"bnc_validate"] isEqualToString:@"true"])) {
22012201
NSString* referringLink = [self.class returnNonUniversalLink:latestReferringParams[@"~referring_link"] ];
22022202
NSURLComponents *comp = [NSURLComponents componentsWithURL:[NSURL URLWithString:referringLink]
22032203
resolvingAgainstBaseURL:NO];

Examples/UITestBed/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# UITestBed
2+
3+
This is a small app for testing all the Branch features and is easy to automate with automated Xcode UITests.
4+
5+
## Test Links
6+
Some links for tests:
7+
8+
https://branch-uitestbed.app.link/MAzO7DEW6M
9+

Examples/UITestBed/UITestBed.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
/* Begin PBXFileReference section */
137137
4D0E07D01FCDF7810074E026 /* SafariServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SafariServices.framework; path = System/Library/Frameworks/SafariServices.framework; sourceTree = SDKROOT; };
138138
4D0E07D11FCDF7920074E026 /* iAd.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iAd.framework; path = System/Library/Frameworks/iAd.framework; sourceTree = SDKROOT; };
139+
4D0F56B720B38394003D6607 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
139140
4D12B9F720A100EB00E5B1DB /* UITestBed.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = UITestBed.strings; sourceTree = "<group>"; };
140141
4D1683262098BD3E008819E3 /* BranchSetIdentityRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchSetIdentityRequestTests.m; sourceTree = "<group>"; };
141142
4D1683272098BD3E008819E3 /* BranchCloseRequestTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchCloseRequestTests.m; sourceTree = "<group>"; };
@@ -350,6 +351,7 @@
350351
4DFF2B601EEF3B150043F840 = {
351352
isa = PBXGroup;
352353
children = (
354+
4D0F56B720B38394003D6607 /* README.md */,
353355
4D5ACEEC1FB382040099A56F /* BranchSDK.xcodeproj */,
354356
4D1683242098BD3E008819E3 /* Branch-SDK-Tests */,
355357
4DFF2B6B1EEF3B150043F840 /* UITestBed */,

Examples/UITestBed/UITestBed/TBAppDelegate.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ - (BOOL)application:(UIApplication *)application
3232
// Set to YES for testing GDPR compliance.
3333
// [Branch setTrackingDisabled:YES];
3434

35-
#if 0
36-
// This simulates opt-in tracking.
35+
#if 0
36+
// This simulates tracking opt-in, rather than tracking opt-out.
3737
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"hasRunBefore"]) {
3838
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasRunBefore"];
3939
[Branch setTrackingDisabled:YES];
4040
}
41-
#endif
41+
#endif
4242

4343
// Initialize Branch
4444
Branch *branch = [Branch getInstance];
45+
46+
// This starts the Branch integration validation. Remove for normal use.
47+
// [branch validateSDKIntegration];
4548

4649
// Comment / un-comment to toggle debugging
4750
[branch setDebug];

0 commit comments

Comments
 (0)