Skip to content

Commit a4be8ff

Browse files
committed
SDK-479 improve test reliability. DeviceInfo no longer shadows the static user agent variable with an instance variable.
1 parent 53c95bb commit a4be8ff

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Branch-SDK/Branch-SDK/BNCDeviceInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
@property (atomic, copy, readonly) NSString* country; //!< The iso2 Country name (us, in,etc).
4040
@property (atomic, copy, readonly) NSString* language; //!< The iso2 language code (en, ml).
41-
@property (atomic, copy, readonly) NSString* browserUserAgent; //!< Simple user agent string.
4241
@property (atomic, copy, readonly) NSString* localIPAddress; //!< The current local IP address.
4342
@property (atomic, copy, readonly) NSArray<NSString*> *allIPAddresses; //!< All local IP addresses.
4443
//----------Methods----------------//

Branch-SDK/Branch-SDK/BNCDeviceInfo.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ - (id)init {
174174

175175
_country = [BNCDeviceInfo bnc_country].copy;
176176
_language = [BNCDeviceInfo bnc_language].copy;
177-
_browserUserAgent = [BNCDeviceInfo userAgentString].copy;
178177
_extensionType = self.class.extensionType.copy;
179178
_branchSDKVersion = [NSString stringWithFormat:@"ios%@", BNC_SDK_VERSION];
180179
_applicationVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
@@ -355,7 +354,6 @@ - (NSDictionary*) v2dictionary {
355354
} else {
356355
addString(adId, idfa);
357356
}
358-
addString(browserUserAgent, user_agent);
359357
addString(country, country);
360358
addString(language, language);
361359
addString(brandName, brand);
@@ -368,6 +366,8 @@ - (NSDictionary*) v2dictionary {
368366
addString(localIPAddress, local_ip);
369367

370368
#include "BNCFieldDefines.h"
369+
370+
dictionary[@"user_agent"] = [BNCDeviceInfo userAgentString];
371371

372372
if (!self.isAdTrackingEnabled)
373373
dictionary[@"limit_ad_tracking"] = (__bridge NSNumber*) kCFBooleanTrue;

Branch-SDK/Branch-SDK/BNCUserAgentCollector.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,21 @@ - (void)saveUserAgent:(NSString *)userAgent forSystemBuildVersion:(NSString *)sy
7272
// collect user agent from webkit. this is expensive.
7373
- (void)collectUserAgentWithCompletion:(void (^)(NSString *userAgent))completion {
7474
dispatch_async(dispatch_get_main_queue(), ^{
75-
self.webview = [[WKWebView alloc] initWithFrame:CGRectZero];
75+
if (!self.webview) {
76+
self.webview = [[WKWebView alloc] initWithFrame:CGRectZero];
77+
}
78+
7679
[self.webview evaluateJavaScript:@"navigator.userAgent;" completionHandler:^(id _Nullable response, NSError * _Nullable error) {
7780
if (completion) {
78-
completion(response);
79-
80-
// release the webview
81-
self.webview = nil;
81+
if (response) {
82+
// release the webview
83+
self.webview = nil;
84+
85+
completion(response);
86+
} else {
87+
// retry if we failed to obtain user agent. This occasionally occurs on simulator.
88+
[self collectUserAgentWithCompletion:completion];
89+
}
8290
}
8391
}];
8492
});

Branch-SDK/Branch-SDK/Networking/BNCServerInterface.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
894894
[self safeSetValue:deviceInfo.screenWidth forKey:BRANCH_REQUEST_KEY_SCREEN_WIDTH onDict:dict];
895895
[self safeSetValue:deviceInfo.screenHeight forKey:BRANCH_REQUEST_KEY_SCREEN_HEIGHT onDict:dict];
896896

897-
[self safeSetValue:deviceInfo.browserUserAgent forKey:@"user_agent" onDict:dict];
897+
[self safeSetValue:[BNCDeviceInfo userAgentString] forKey:@"user_agent" onDict:dict];
898898
[self safeSetValue:deviceInfo.country forKey:@"country" onDict:dict];
899899
[self safeSetValue:deviceInfo.language forKey:@"language" onDict:dict];
900900
dict[@"local_ip"] = deviceInfo.localIPAddress;

0 commit comments

Comments
 (0)