Skip to content

Commit cbe38ad

Browse files
[release] 1.39.3
1 parent c16676f commit cbe38ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2986
-86
lines changed

Branch-SDK/BNCConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
NSString * const BNC_API_BASE_URL = @"https://api2.branch.io";
1212
NSString * const BNC_API_VERSION = @"v1";
1313
NSString * const BNC_LINK_URL = @"https://bnc.lt";
14-
NSString * const BNC_SDK_VERSION = @"1.39.2";
14+
NSString * const BNC_SDK_VERSION = @"1.39.3";

Branch-SDK/BNCLog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ extern NSString *_Nonnull BNCLogStringFromLogLevel(BNCLogLevel level);
4949
*/
5050
extern BNCLogLevel BNCLogLevelFromString(NSString*_Null_unspecified string);
5151

52+
///@name Pre-defined log message handlers --
53+
typedef void (*BNCLogOutputFunctionPtr)(NSDate*_Nonnull timestamp, BNCLogLevel level, NSString*_Nullable message);
54+
55+
///@param functionPtr A pointer to the logging function. Setting the parameter to NULL will flush
56+
/// and close the currently set log function and future log messages will be
57+
/// ignored until a non-NULL logging function is set.
58+
extern void BNCLogSetOutputFunction(BNCLogOutputFunctionPtr _Nullable functionPtr);
59+
5260
#pragma mark - BNCLogWriteMessage
5361

5462
/// The main logging function used in the variadic logging defines.

Branch-SDK/BNCLog.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#define _countof(array) (sizeof(array)/sizeof(array[0]))
1414

15+
static BNCLogOutputFunctionPtr bnc_LoggingFunction = nil; // Default to just NSLog output.
16+
1517
// A fallback attempt at logging if an error occurs in BNCLog.
1618
// BNCLog can't log itself, but if an error occurs it uses this simple define:
1719
extern void BNCLogInternalError(NSString *message);
@@ -62,6 +64,9 @@ BNCLogLevel BNCLogLevelFromString(NSString*string) {
6264
return BNCLogLevelNone;
6365
}
6466

67+
void BNCLogSetOutputFunction(BNCLogOutputFunctionPtr _Nullable logFunction) {
68+
bnc_LoggingFunction = logFunction;
69+
}
6570
#pragma mark - BNCLogInternal
6671

6772
void BNCLogWriteMessage(
@@ -98,5 +103,7 @@ void BNCLogWriteMessage(
98103

99104
if (logLevel >= bnc_LogDisplayLevel) {
100105
NSLog(@"%@", s); // Upgrade this to unified logging when we can.
106+
if (bnc_LoggingFunction)
107+
bnc_LoggingFunction([NSDate date], logLevel, message);
101108
}
102109
}

Branch-SDK/BNCServerInterface.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params
403403
NSData *postData = [BNCEncodingUtils encodeDictionaryToJsonData:preparedParams];
404404
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
405405

406-
BNCLogDebug([NSString stringWithFormat:@"URL: %@.", url]);
406+
BNCLogDebug([NSString stringWithFormat:@"URL: %@.\n", url]);
407407
BNCLogDebug([NSString stringWithFormat:@"Body: %@\nJSON: %@.",
408408
preparedParams,
409409
[[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding]]

Branch-SDK/BNCSystemObserver.m

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,37 @@ + (NSString *)getUniqueHardwareId:(BOOL *)isReal
5555
}
5656

5757
+ (NSString *)appleAttributionToken {
58+
// token is not available on simulator
59+
if ([self isSimulator]) {
60+
return nil;
61+
}
62+
63+
__block NSString *token = nil;
64+
5865
#if !TARGET_OS_TV
5966
if (@available(iOS 14.3, *)) {
60-
NSError *error;
61-
NSString *appleAttributionToken = [AAAttribution attributionTokenWithError:&error];
62-
if (!error) {
63-
return appleAttributionToken;
67+
68+
// We are getting reports on iOS 14.5 that this API can hang, adding a short timeout for now.
69+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
70+
71+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
72+
NSError *error;
73+
NSString *appleAttributionToken = [AAAttribution attributionTokenWithError:&error];
74+
if (!error) {
75+
token = appleAttributionToken;
76+
}
77+
dispatch_semaphore_signal(semaphore);
78+
});
79+
80+
// Apple said this API should respond within 50ms, lets give up after 500 ms
81+
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(500 * NSEC_PER_MSEC)));
82+
if (token == nil) {
83+
BNCLogDebug([NSString stringWithFormat:@"AppleAttributionToken request timed out"]);
6484
}
6585
}
6686
#endif
67-
return nil;
87+
88+
return token;
6889
}
6990

7091
+ (NSString *)getAdId {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// UITestOpenNInstall.m
3+
// Branch-TestBed-UITests
4+
//
5+
// Created by Nidhi on 3/10/21.
6+
// Copyright © 2021 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "UITestCaseTestBed.h"
10+
#import <Foundation/Foundation.h>
11+
12+
@interface UITestCase0OpenNInstall : UITestCaseTestBed
13+
14+
@end
15+
16+
@implementation UITestCase0OpenNInstall
17+
18+
- (void)setUp {
19+
[super setUp];
20+
}
21+
22+
- (void)tearDown {
23+
}
24+
/*
25+
* Test Case :
26+
* 1.1 First initSession call results in API call to /v1/install or /v1/open
27+
* 1.2 Subsequent initSession calls result in API call to /v1/open
28+
*/
29+
- (void)test0Install {
30+
31+
// Launch App and Disable Tracking
32+
XCUIApplication *app = [[XCUIApplication alloc] init];
33+
[app launch];
34+
[self disableTracking:FALSE];
35+
36+
// Press Button "Load Logs for Last Command" and copy logs
37+
XCUIElementQuery *tablesQuery = app.tables;
38+
[tablesQuery.staticTexts[@"Load Logs for Last Command"] tap];
39+
XCUIElement *deeplinkdataTextView = app.textViews[@"DeepLinkData"];
40+
[deeplinkdataTextView tap];
41+
NSString *prevLogResults = app.textViews[@"DeepLinkData"].value;
42+
43+
// Parse logs
44+
NSString *url;
45+
NSDictionary *json;
46+
NSString *status;
47+
NSDictionary *dataJson;
48+
[self parseURL:&url andJSON:&json andStatus:&status andDataJSON:&dataJson FromLogs:prevLogResults];
49+
50+
// Check url contains /v1/install
51+
XCTAssertNotNil(url);
52+
XCTAssertNotNil(json);
53+
XCTAssertTrue([url containsString:@"/v1/install"]);
54+
55+
// Get and Assert device_fingerprint_id & identity_id
56+
NSNumber *device_fingerprint_id = [dataJson objectForKey:@"device_fingerprint_id"];
57+
NSNumber *identity_id = [dataJson objectForKey:@"identity_id"];
58+
XCTAssertNotNil(identity_id);
59+
XCTAssertNotNil(device_fingerprint_id);
60+
61+
//Re-launch App
62+
[app.navigationBars[@"Branch-TestBed"].buttons[@"Branch-TestBed"] tap];
63+
[app terminate];
64+
[app launch];
65+
66+
// Load logs and assert -
67+
// - URL contains /v1/open
68+
// - device_fingerprint_id is the same as returned above
69+
// - identity_id is the same as returned above
70+
[tablesQuery/*@START_MENU_TOKEN@*/.staticTexts[@"Load Logs for Last Command"]/*[[".cells",".buttons[@\"Load Logs for Last Command\"].staticTexts[@\"Load Logs for Last Command\"]",".staticTexts[@\"Load Logs for Last Command\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/ tap];
71+
deeplinkdataTextView = app.textViews[@"DeepLinkData"];
72+
[deeplinkdataTextView tap];
73+
prevLogResults = app.textViews[@"DeepLinkData"].value;
74+
[self parseURL:&url andJSON:&json andStatus:&status andDataJSON:&dataJson FromLogs:prevLogResults];
75+
76+
XCTAssertTrue([url containsString:@"/v1/open"]);
77+
78+
XCTAssertNotNil([json valueForKey:@"identity_id"]);
79+
NSNumber *newID = [NSNumber numberWithInteger: [[json objectForKey:@"identity_id"] integerValue]] ;
80+
XCTAssertTrue([newID isEqualToNumber:identity_id]);
81+
82+
XCTAssertNotNil([json valueForKey:@"device_fingerprint_id"]);
83+
NSNumber *newFPID = [NSNumber numberWithInteger: [[json objectForKey:@"device_fingerprint_id"] integerValue]] ;
84+
XCTAssertTrue([newFPID isEqualToNumber:device_fingerprint_id]);
85+
XCTAssertTrue([status containsString:@"200"]);
86+
}
87+
88+
/*
89+
When a link is clicked with the app installed, it opens the app
90+
- the call to /v1/open should include information about the link clicked
91+
- the response from /v1/open should include deep link data inside the `data` object
92+
*/
93+
- (void) testOpenAppFromWebPage
94+
{
95+
[self clickLinkInWebPage:@"TestWebPage.html"];
96+
97+
XCUIApplication *app = [[XCUIApplication alloc] init];
98+
if ([ app waitForExistenceWithTimeout:15] != NO) {
99+
sleep(1);
100+
NSString *deepLinkData = app.textViews[@"DeepLinkData"].value;
101+
XCTAssertTrue([deepLinkData containsString:self.deeplinkDataToCheck]);
102+
} else {
103+
XCTFail("Application not launched");
104+
}
105+
}
106+
107+
@end
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// UITestCaseMisc.m
3+
// Branch-TestBed-UITests
4+
//
5+
// Created by Nidhi on 2/26/21.
6+
// Copyright © 2021 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "UITestCaseTestBed.h"
10+
#import "Branch.h"
11+
#import "BranchEvent.h"
12+
13+
@interface UITestCaseMisc : UITestCaseTestBed
14+
15+
@end
16+
17+
@implementation UITestCaseMisc
18+
19+
- (void)setUp {
20+
[super setUp];
21+
}
22+
23+
- (void)tearDown {
24+
}
25+
26+
- (void)testShareLink {
27+
28+
// Tap on 'Creat Branch Link' and then 'Share Link'
29+
XCUIApplication *app = [[XCUIApplication alloc] init];
30+
[app launch];
31+
[self disableTracking:FALSE];
32+
XCUIElementQuery *tablesQuery = app.tables;
33+
[tablesQuery/*@START_MENU_TOKEN@*/.staticTexts[@"Create Branch Link"]/*[[".cells",".buttons[@\"Create Branch Link\"].staticTexts[@\"Create Branch Link\"]",".staticTexts[@\"Create Branch Link\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/ tap];
34+
[tablesQuery.staticTexts[@"Share Link"] tap];
35+
sleep(3);
36+
37+
// Copy Link
38+
[[[[app/*@START_MENU_TOKEN@*/.collectionViews/*[[".otherElements[@\"ActivityListView\"].collectionViews",".collectionViews"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.buttons[@"Copy"].otherElements containingType:XCUIElementTypeImage identifier:@"copy"] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element tap];
39+
sleep(3);
40+
41+
// Assert Link is copied in Pasteboard
42+
NSString *pasteboardString = [UIPasteboard generalPasteboard].string;
43+
if ([pasteboardString containsString:@"Shared through 'Pasteboard'"] != YES) {
44+
XCTFail("Link not copied");
45+
}
46+
}
47+
48+
- (void)testCreateAndOpenURL {
49+
50+
XCUIApplication *app = [[XCUIApplication alloc] init];
51+
[app launch];
52+
[self disableTracking:FALSE];
53+
54+
//Tap "Create Branch Link" and assert text Field "Branch Link" shows link
55+
XCUIElementQuery *tablesQuery = app.tables;
56+
[tablesQuery.staticTexts[@"Create Branch Link"] tap];
57+
XCUIElement *branchLinkTextField = tablesQuery.textFields[@"Branch Link"];
58+
NSString *shortURL = branchLinkTextField.value;
59+
XCTAssertNotNil(shortURL);
60+
61+
// Tap "Open Branch Link" and assert deep link data
62+
[tablesQuery.buttons[@"Open Branch Link"] tap];
63+
sleep(1);
64+
NSString *deepLinkData = app.textViews[@"DeepLinkData"].value;
65+
self.deeplinkDataToCheck = @"This text was embedded as data in a Branch link with the following characteristics:\n\ncanonicalUrl: https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\n title: Content Title\n contentDescription: My Content Description\n imageUrl: https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\n";
66+
NSLog(@"%@" , self.deeplinkDataToCheck);
67+
XCTAssertTrue([deepLinkData containsString:self.deeplinkDataToCheck]);
68+
69+
}
70+
71+
- (void)testReferringParams
72+
{
73+
// Launch App, disable tracking and logout
74+
XCUIApplication *app = [[XCUIApplication alloc] init];
75+
[app launch];
76+
[self disableTracking:FALSE];
77+
XCUIElementQuery *tablesQuery = app.tables;
78+
[tablesQuery/*@START_MENU_TOKEN@*/.staticTexts[@"SimulateLogout"]/*[[".cells",".buttons[@\"SimulateLogout\"].staticTexts[@\"SimulateLogout\"]",".staticTexts[@\"SimulateLogout\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/ tap];
79+
[app.alerts[@"Logout succeeded"].scrollViews.otherElements.buttons[@"OK"] tap];
80+
81+
// Tap 'View FirstReferringParams' and copy params
82+
XCUIElement *branchTestbedButton = app.navigationBars[@"Branch-TestBed"].buttons[@"Branch-TestBed"];
83+
XCUIElement *viewFirstreferringparamsStaticText = tablesQuery.staticTexts[@"View FirstReferringParams"];
84+
[viewFirstreferringparamsStaticText tap];
85+
NSString *viewFirstreferringString = app.textViews[@"DeepLinkData"].value;
86+
XCTAssertTrue([viewFirstreferringString containsString:@"{\n}"]);
87+
[branchTestbedButton tap];
88+
89+
// Tap 'View LatestReferringParams' and copy params
90+
XCUIElement *viewLatestreferringparamsStaticText = tablesQuery.staticTexts[@"View LatestReferringParams"];
91+
[viewLatestreferringparamsStaticText tap];
92+
NSString *viewLatesttreferringString = app.textViews[@"DeepLinkData"].value;
93+
XCTAssertTrue([viewLatesttreferringString containsString:@"{\n}"]);
94+
[branchTestbedButton tap];
95+
96+
// Tap "Set User ID" and then Tap 'View FirstReferringParams' & 'View LatestReferringParams' and copy params again
97+
[tablesQuery.buttons[@"Set User ID"] tap];
98+
[branchTestbedButton tap];
99+
sleep(1);
100+
[viewFirstreferringparamsStaticText tap];
101+
viewFirstreferringString = app.textViews[@"DeepLinkData"].value;
102+
[branchTestbedButton tap];
103+
[viewLatestreferringparamsStaticText tap];
104+
viewLatesttreferringString = app.textViews[@"DeepLinkData"].value;
105+
[branchTestbedButton tap];
106+
107+
// Re-launch app.
108+
[app terminate];
109+
[app launch];
110+
111+
// Tap on 'View FirstReferringParams' & 'View LatestReferringParams' again and check viewFirstreferringparamsStaticText is still same and viewLatestreferringparamsStaticText shows latest paramms.
112+
[viewFirstreferringparamsStaticText tap];
113+
NSString *viewFirstreferringStringNew = app.textViews[@"DeepLinkData"].value;
114+
[branchTestbedButton tap];
115+
XCTAssertTrue([viewFirstreferringString isEqualToString:viewFirstreferringStringNew]);
116+
[viewLatestreferringparamsStaticText tap];
117+
viewLatesttreferringString = app.textViews[@"DeepLinkData"].value;
118+
[branchTestbedButton tap];
119+
120+
NSString *viewLatesttreferringStringNew =@"{\n \"+clicked_branch_link\" = 0;\n \"+is_first_session\" = 0;\n}";
121+
122+
XCTAssertTrue([viewLatesttreferringString isEqualToString:viewLatesttreferringStringNew]);
123+
124+
}
125+
126+
- (void)testFBParams
127+
{
128+
XCUIApplication *app = [[XCUIApplication alloc] init];
129+
[app launch];
130+
[self disableTracking:FALSE];
131+
132+
XCUIElementQuery *tablesQuery = [[XCUIApplication alloc] init].tables;
133+
[tablesQuery/*@START_MENU_TOKEN@*/.buttons[@"Set FB Params"]/*[[".cells.buttons[@\"Set FB Params\"]",".buttons[@\"Set FB Params\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
134+
setFBParams = TRUE;
135+
checkFBParams = TRUE;
136+
[self sendEvent:BranchStandardEventAddToCart];
137+
XCUIElement *branchTestbedButton = app.navigationBars[@"Branch-TestBed"].buttons[@"Branch-TestBed"];
138+
[branchTestbedButton tap];
139+
[tablesQuery/*@START_MENU_TOKEN@*/.buttons[@"Clear FB Params"]/*[[".cells.buttons[@\"Clear FB Params\"]",".buttons[@\"Clear FB Params\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
140+
setFBParams = FALSE;
141+
[self sendEvent:BranchStandardEventAddToCart];
142+
checkFBParams = FALSE;
143+
}
144+
145+
@end

0 commit comments

Comments
 (0)