Skip to content

Commit c4b53a9

Browse files
[SDK-2017] Remove v1/profile and v1/logout calls
1 parent 811dc52 commit c4b53a9

File tree

8 files changed

+77
-68
lines changed

8 files changed

+77
-68
lines changed

Branch/BNCNetworkAPIService.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ - (void) postOperationForAPIServiceName:(NSString*)serviceName
205205
}
206206
} else {
207207
NSString *endpoint = url.path;
208-
if ([endpoint isEqualToString:@"/v1/open"]) {
208+
if ([endpoint isEqualToString:@"/v1/open"] || [endpoint isEqualToString:@"/v1/install"]) {
209209
dictionary[@"identity"] = self.settings.userIdentityForDeveloper;
210210
}
211211
}
@@ -417,8 +417,6 @@ - (void) main {
417417

418418
if (self.session.linkCreationURL.length)
419419
self.settings.linkCreationURL = self.session.linkCreationURL;
420-
if (self.session.userIdentityForDeveloper.length)
421-
self.settings.userIdentityForDeveloper = self.session.userIdentityForDeveloper;
422420
if (self.session.sessionID.length)
423421
self.settings.sessionID = self.session.sessionID;
424422

Branch/BranchMainClass.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,27 @@ so that Branch can handle the passed URL.
137137

138138
/**
139139
Set the user's identity to an ID used by your system, so that it is identifiable by you elsewhere. Receive
140-
a completion callback, notifying you whether it succeeded or failed.
140+
a completion callback.
141141
142142
@param userId The ID Branch should use to identify this user.
143-
@param completion The callback to be called once the request has completed (success or failure).
143+
@param completion The callback to be called once the identity has been set.
144144
145145
@warning If you use the same ID between users on different sessions / devices, their actions will be merged.
146-
@warning This request is not removed from the queue upon failure -- it will be retried until it succeeds.
147-
The callback will only ever be called once, though.
148146
@warning You should call `logout` before calling `setIdentity:` a second time.
149147
*/
150148
- (void)setUserIdentity:(NSString*)userId
151149
completion:(void (^_Nullable)(BranchSession*_Nullable session, NSError*_Nullable error))completion;
152150

151+
/**
152+
Set the user's identity to an ID used by your system, so that it is identifiable by you elsewhere.
153+
154+
@param userId The ID Branch should use to identify this user.
155+
156+
@warning If you use the same ID between users on different sessions / devices, their actions will be merged.
157+
@warning You should call `logout` before calling `setIdentity:` a second time.
158+
*/
159+
- (void)setUserIdentity:(NSString*)userId;
160+
153161
/**
154162
Retrieve the user identity set via setUserIdentity
155163
@@ -181,6 +189,12 @@ so that Branch can handle the passed URL.
181189
*/
182190
- (void) logoutWithCompletion:(void (^_Nullable)(NSError*_Nullable error))completion;
183191

192+
/**
193+
Clear all of the current user's session items.
194+
195+
*/
196+
- (void) logout;
197+
184198
/**
185199
Generates a Branch short URL that describes the content described in the Branch Universal Object and
186200
has the passed link properties.

Branch/BranchMainClass.m

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -586,31 +586,37 @@ - (BOOL) userTrackingIsDisabled {
586586

587587
#pragma mark - User Identity
588588

589+
- (void)setUserIdentity:(NSString*)userID {
590+
[self setUserIdentity:userID completion:nil];
591+
}
592+
589593
- (void)setUserIdentity:(NSString*)userID
590-
completion:(void (^_Nullable)(BranchSession*session, NSError*_Nullable error))completion {
594+
completion:(void (^_Nullable)(BranchSession*session, NSError*_Nullable error))completion {
595+
591596
if (!userID || [self.settings.userIdentityForDeveloper isEqualToString:userID]) {
592597
if (completion) completion(nil, nil); // TODO: fix the session.
593598
return;
594599
}
595-
// [self initSessionIfNeededAndNotInProgress];
596-
NSMutableDictionary *dictionary = [NSMutableDictionary new];
597-
dictionary[@"identity"] = userID;
598-
dictionary[@"randomized_device_token"] = self.settings.randomizedDeviceToken;
599-
dictionary[@"session_id"] = self.settings.sessionID;
600-
dictionary[@"randomized_bundle_token"] = self.settings.randomizedBundleToken;
601-
[self.networkAPIService appendV1APIParametersWithDictionary:dictionary];
602-
[self.networkAPIService postOperationForAPIServiceName:@"v1/profile"
603-
dictionary:dictionary
604-
completion:^(BNCNetworkAPIOperation*_Nonnull operation) {
605-
BNCPerformBlockOnMainThreadAsync(^{
606-
if (!operation.error) {
607-
self.settings.userIdentityForDeveloper = userID;
608-
operation.session.userIdentityForDeveloper = userID;
609-
}
610-
if (completion) completion(operation.session, operation.error);
611-
});
612-
}
613-
];
600+
601+
BranchSession *session = [BranchSession new];
602+
603+
if (self.settings.userTrackingDisabled) {
604+
[self.settings clearUserIdentifyingInformation];
605+
NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError];
606+
BNCLogError(@"Branch error: %@.", error);
607+
if (completion) completion(session, error);
608+
return;
609+
}
610+
611+
BNCPerformBlockOnMainThreadAsync(^{
612+
session.userIdentityForDeveloper = userID;
613+
session.sessionID = self.settings.sessionID;
614+
615+
self.settings.userIdentityForDeveloper = userID;
616+
617+
if (completion) completion(session, nil);
618+
});
619+
614620
}
615621

616622
- (nullable NSString *)getUserIdentity {
@@ -625,22 +631,19 @@ - (nullable NSString *)getKey {
625631
return self.configuration.key;
626632
}
627633

628-
629634
#pragma mark - Logout
630635

636+
- (void)logout {
637+
[self logoutWithCompletion:nil];
638+
}
639+
631640
- (void)logoutWithCompletion:(void (^_Nullable)(NSError*_Nullable))completion {
632-
NSMutableDictionary *dictionary = [NSMutableDictionary new];
633-
dictionary[@"randomized_device_token"] = self.settings.randomizedDeviceToken;
634-
dictionary[@"session_id"] = self.settings.sessionID;
635-
dictionary[@"randomized_bundle_token"] = self.settings.randomizedBundleToken;
636-
[self.networkAPIService appendV1APIParametersWithDictionary:dictionary];
637-
[self.networkAPIService postOperationForAPIServiceName:@"v1/logout"
638-
dictionary:dictionary
639-
completion:^(BNCNetworkAPIOperation * _Nonnull operation) {
640-
if (!operation.error)
641-
self.settings.userIdentityForDeveloper = nil;
642-
BNCPerformBlockOnMainThreadAsync(^{ if (completion) completion(operation.error); });
643-
}];
641+
642+
BNCPerformBlockOnMainThreadAsync(^{
643+
self.settings.userIdentityForDeveloper = nil;
644+
645+
if (completion) completion(nil);
646+
});
644647
}
645648

646649
#pragma mark - Miscellaneous

BranchTests/BNCDevice.Test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ - (void)testDevice {
3333

3434
XCTAssertTrue(
3535
device.systemVersion.doubleValue > 10.15 &&
36-
device.systemVersion.doubleValue <= 13
36+
device.systemVersion.doubleValue <= 14
3737
);
3838
XCTAssertTrue(BNCTestStringMatchesRegex(device.systemBuildVersion, @"^[0-9A-Za-z]+$"));
3939
XCTAssertTrue(

BranchTests/BNCTestNetworkService.Test.m

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,17 @@ - (void) testTheTestService {
2626
XCTestExpectation*requestExpectation = [self expectationWithDescription:@"testTheTestService-1"];
2727
BNCTestNetworkService.requestHandler = ^ id<BNCNetworkOperationProtocol> (NSMutableURLRequest*request) {
2828
XCTAssertEqualObjects(request.HTTPMethod, @"POST");
29-
XCTAssertEqualObjects(request.URL.path, @"/v1/logout");
30-
NSMutableDictionary*truthDictionary = [self mutableDictionaryFromBundleJSONWithKey:@"logoutRequest"];
29+
XCTAssertEqualObjects(request.URL.path, @"/v1/install");
30+
NSMutableDictionary*truthDictionary = [self mutableDictionaryFromBundleJSONWithKey:@"BranchInstallRequestMac"];
3131
NSMutableDictionary*requestDictionary = [BNCTestNetworkService mutableDictionaryFromRequest:request];
3232
XCTAssertNotNil(truthDictionary);
3333
XCTAssertNotNil(requestDictionary);
3434

3535
[requestExpectation fulfill];
36-
NSString*responseString = [self stringFromBundleJSONWithKey:@"logoutResponse"];
36+
NSString*responseString = [self stringFromBundleJSONWithKey:@"BranchOpenResponseMac"];
3737
return [BNCTestNetworkService operationWithRequest:request response:responseString];
3838
};
39-
40-
[branch.networkAPIService clearNetworkQueue];
41-
XCTestExpectation*expectation = [self expectationWithDescription:@"testTheTestService-2"];
42-
[branch logoutWithCompletion:^(NSError * _Nullable error) {
43-
XCTAssertNil(error);
44-
[expectation fulfill];
45-
}];
46-
39+
4740
[self waitForExpectationsWithTimeout:5.0 handler:nil];
4841
}
4942

BranchTests/BranchMainClass.Test.m

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ - (void) testSetIdentity {
6666
NSString*const kUserIdentity = @"Nada";
6767
Branch*branch = self.branch;
6868
XCTestExpectation *expectation = [self expectationWithDescription:@"testSetIdentity"];
69-
[branch setUserIdentity:kUserIdentity
70-
completion:^ (BranchSession * _Nullable session, NSError * _Nullable error) {
69+
[branch setUserIdentity:kUserIdentity completion:^ (BranchSession * _Nullable session, NSError * _Nullable error) {
7170
XCTAssertNil(error);
7271
XCTAssertEqualObjects(session.userIdentityForDeveloper, kUserIdentity);
7372
[expectation fulfill];
7473
}
7574
];
76-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
75+
[self waitForExpectationsWithTimeout:0.1 handler:nil];
7776
XCTAssertTrue(branch.userIdentityIsSet);
7877

7978
[self resetExpectations];
@@ -82,7 +81,7 @@ - (void) testSetIdentity {
8281
XCTAssertNil(error);
8382
[expectation fulfill];
8483
}];
85-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
84+
[self waitForExpectationsWithTimeout:0.1 handler:nil];
8685
XCTAssertFalse(branch.userIdentityIsSet);
8786
}
8887

@@ -102,7 +101,7 @@ - (void)testGetUserIdentityEmail {
102101
XCTAssertEqualObjects(session.userIdentityForDeveloper, userIdentity);
103102
[expectation fulfill];
104103
}];
105-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
104+
[self waitForExpectationsWithTimeout:0.1 handler:nil];
106105
XCTAssertTrue(branch.userIdentityIsSet);
107106
XCTAssertTrue([userIdentity isEqualToString:[branch getUserIdentity]]);
108107
}
@@ -149,13 +148,14 @@ - (void) testShortLinksWithoutBUO1 {
149148
NSString *channel = @"facebook";
150149
NSString *feature = @"sharing";
151150
NSArray *tags = @[ @"t1", @"t2" ];
152-
NSString *alias = @"testAlias";
153-
151+
NSString *alias = [NSString stringWithFormat:@"testAlias_%@", [NSUUID UUID].UUIDString];
152+
154153
XCTestExpectation *expectation = [self expectationWithDescription:@"testShortLinksWithoutBUO"];
155154
[self.branch branchShortUrlWithParams:( NSDictionary * _Nullable )params andChannel:( NSString * _Nullable )channel andFeature:(NSString * _Nullable)feature andTags:(NSArray * _Nullable)tags andAlias:(NSString * _Nullable)alias andCallback:^ (NSURL * _Nullable shortURL, NSError * _Nullable error) {
156155
XCTAssertNil(error);
157156
XCTAssertNotNil(shortURL);
158-
XCTAssertTrue([shortURL.absoluteString isEqualToString:@"https://testbed-mac.app.link/testAlias"]);
157+
NSString *expectedURL = [NSString stringWithFormat:@"https://testbed-mac.app.link/%@", alias];
158+
XCTAssertTrue([shortURL.absoluteString isEqualToString:expectedURL]);
159159
[expectation fulfill];
160160
}];
161161
[self waitForExpectationsWithTimeout:5.0 handler:nil];
@@ -167,13 +167,14 @@ - (void) testShortLinksWithoutBUO2 {
167167
NSString *channel = @"facebook";
168168
NSString *feature = @"sharing";
169169
NSArray *tags = @[ @"t1", @"t2" ];
170-
NSString *alias = @"testAlias";
171-
170+
NSString *alias = [NSString stringWithFormat:@"testAlias_%@", [NSUUID UUID].UUIDString];
171+
172172
XCTestExpectation *expectation = [self expectationWithDescription:@"testShortLinksWithoutBUO"];
173173
[self.branch branchShortUrlWithParams:( NSDictionary * _Nullable )params andChannel:( NSString * _Nullable )channel andFeature:(NSString * _Nullable)feature andTags:(NSArray * _Nullable)tags andAlias:(NSString * _Nullable)alias andCallback:^ (NSURL * _Nullable shortURL, NSError * _Nullable error) {
174174
XCTAssertNil(error);
175175
XCTAssertNotNil(shortURL);
176-
XCTAssertTrue([shortURL.absoluteString isEqualToString:@"https://testbed-mac.app.link/testAlias"]);
176+
NSString *expectedURL = [NSString stringWithFormat:@"https://testbed-mac.app.link/%@", alias];
177+
XCTAssertTrue([shortURL.absoluteString isEqualToString:expectedURL]);
177178
[expectation fulfill];
178179
}];
179180
[self waitForExpectationsWithTimeout:5.0 handler:nil];

Examples/TestBed-macOS/TestBed-macOS/APPActionItemView.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>

Examples/TestBed-macOS/TestBed-macOS/APPViewController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ - (IBAction) showConfiguration:(id)sender {
160160

161161
- (IBAction) setIdentity:(id)sender {
162162
[self clearUIFields];
163-
[[Branch sharedInstance] setUserIdentity:@"Bob" completion:^ (BranchSession*session, NSError*error) {
163+
[[Branch sharedInstance] setUserIdentity:@"BranchUser123" completion:^ (BranchSession*session, NSError*error) {
164164
self.stateField.stringValue =
165-
[NSString stringWithFormat:@"Set Identity: '%@'", session.userIdentityForDeveloper];
165+
[NSString stringWithFormat:@"Set Identity: '%@'", [Branch sharedInstance].getUserIdentity];
166166
self.errorField.stringValue = [self errorMessage:error];
167167
}];
168168
}
@@ -171,7 +171,7 @@ - (IBAction) logUserOut:(id)sender {
171171
BNCLogMethodName();
172172
[self clearUIFields];
173173
[[Branch sharedInstance] logoutWithCompletion:^ (NSError*error) {
174-
self.stateField.stringValue = @"Log User Out";
174+
self.stateField.stringValue = [NSString stringWithFormat:@"Logged User Out: '%@'", [Branch sharedInstance].getUserIdentity];
175175
self.errorField.stringValue = [self errorMessage:error];
176176
}];
177177
}

0 commit comments

Comments
 (0)