Skip to content

Commit bf41ae9

Browse files
committed
SDK-562 update the user data dictionary.
1 parent a836f39 commit bf41ae9

File tree

12 files changed

+322
-324
lines changed

12 files changed

+322
-324
lines changed

Branch-SDK-Tests/BNCDeviceInfo.Test.m

Lines changed: 0 additions & 166 deletions
This file was deleted.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// BNCDeviceInfoTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 11/21/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "BNCDeviceInfo.h"
11+
12+
@interface BNCDeviceInfoTests : XCTestCase
13+
@property (nonatomic, strong, readwrite) BNCDeviceInfo *deviceInfo;
14+
@end
15+
16+
@implementation BNCDeviceInfoTests
17+
18+
- (void)setUp {
19+
self.deviceInfo = [BNCDeviceInfo new];
20+
}
21+
22+
- (void)tearDown {
23+
24+
}
25+
26+
- (void)testAppVersion {
27+
// checks test app version
28+
XCTAssert([@"1.1" isEqualToString:self.deviceInfo.applicationVersion]);
29+
}
30+
31+
- (void)testBrandName {
32+
XCTAssert([@"Apple" isEqualToString:self.deviceInfo.brandName]);
33+
}
34+
35+
- (void)testModelName_Simulator {
36+
XCTAssert([@"x86_64" isEqualToString:self.deviceInfo.modelName]);
37+
}
38+
39+
//- (void)testModelName_iPhone7 {
40+
// XCTAssert([@"iPhone9,3" isEqualToString:self.deviceInfo.modelName]);
41+
//}
42+
43+
- (void)testOSName {
44+
XCTAssertNotNil(self.deviceInfo.osName);
45+
XCTAssert([self.deviceInfo.osName isEqualToString:[UIDevice currentDevice].systemName]);
46+
}
47+
48+
- (void)testOSVersion {
49+
XCTAssertNotNil(self.deviceInfo.osVersion);
50+
XCTAssert([self.deviceInfo.osVersion isEqualToString:[UIDevice currentDevice].systemVersion]);
51+
}
52+
53+
- (void)testOSBuildVersion {
54+
XCTAssertNotNil(self.deviceInfo.osBuildVersion);
55+
}
56+
57+
- (void)testExtensionType {
58+
XCTAssert([@"FULL_APP" isEqualToString:self.deviceInfo.extensionType]);
59+
}
60+
61+
- (void)testCpuType_Simulator {
62+
NSNumber *expected = @(7);
63+
XCTAssert([expected isEqualToNumber:self.deviceInfo.cpuType]);
64+
}
65+
66+
//- (void)testCpuType_iPhone7 {
67+
// NSNumber *expected = @(16777228);
68+
// XCTAssert([expected isEqualToNumber:self.deviceInfo.cpuType]);
69+
//}
70+
71+
- (void)testScreenWidth {
72+
XCTAssert(self.deviceInfo.screenWidth.intValue > 320);
73+
}
74+
75+
- (void)testScreenHeight {
76+
XCTAssert(self.deviceInfo.screenHeight.intValue > 320);
77+
}
78+
79+
- (void)testScreenScale {
80+
XCTAssert(self.deviceInfo.screenScale.intValue > 0);
81+
}
82+
83+
- (void)testCarrierName_Simulator {
84+
XCTAssertNil(self.deviceInfo.carrierName);
85+
}
86+
87+
//- (void)testCarrierName_Att {
88+
// XCTAssert([@"AT&T" isEqualToString:self.deviceInfo.carrierName]);
89+
//}
90+
91+
- (void)testLocale {
92+
NSString *locale = [NSLocale currentLocale].localeIdentifier;
93+
XCTAssertNotNil(locale);
94+
XCTAssert([locale isEqualToString:self.deviceInfo.locale]);
95+
}
96+
97+
- (void)testCountry {
98+
NSString *locale = [NSLocale currentLocale].localeIdentifier;
99+
XCTAssertNotNil(locale);
100+
XCTAssert([locale containsString:self.deviceInfo.country]);
101+
}
102+
103+
- (void)testLanguage {
104+
NSString *locale = [NSLocale currentLocale].localeIdentifier;
105+
XCTAssertNotNil(locale);
106+
XCTAssert([locale containsString:self.deviceInfo.language]);
107+
}
108+
109+
- (void)testUserAgentString {
110+
// Currently this method is a trivial pass through to the BNCUserAgentCollector singleton
111+
// Eventually remove the singleton to enable easier testing
112+
}
113+
114+
- (void)testPlugin {
115+
XCTAssertNil(self.deviceInfo.pluginName);
116+
XCTAssertNil(self.deviceInfo.pluginVersion);
117+
118+
NSString *expectedName = @"react native";
119+
NSString *expectedVersion = @"1.0.0";
120+
121+
[self.deviceInfo registerPluginName:expectedName version:expectedVersion];
122+
123+
XCTAssert([expectedName isEqualToString:self.deviceInfo.pluginName]);
124+
XCTAssert([expectedVersion isEqualToString:self.deviceInfo.pluginVersion]);
125+
}
126+
127+
- (void)testLocalIPAddress {
128+
NSString *address = [self.deviceInfo localIPAddress];
129+
XCTAssertNotNil(address);
130+
131+
// shortest ipv4 is 7
132+
XCTAssert(address.length >= 7);
133+
}
134+
135+
// just a sanity check on the V2 dictionary
136+
- (void)testV2Dictionary {
137+
NSDictionary *dict = [self.deviceInfo v2dictionary];
138+
XCTAssertNotNil(dict);
139+
XCTAssertNotNil([dict objectForKey:@"brand"]);
140+
XCTAssertNotNil([dict objectForKey:@"os"]);
141+
XCTAssertNotNil([dict objectForKey:@"sdk"]);
142+
XCTAssertNotNil([dict objectForKey:@"sdk_version"]);
143+
}
144+
145+
@end

Branch-SDK-Tests/BNCLocaleTests.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ - (void)testCounty {
4747
actual = [self.locale countryOS10];
4848
XCTAssert([expected isEqualToString:actual]);
4949

50-
// TODO: verify on iOS 9 device
51-
// This doesn't work on iOS 10+
52-
//actual = [self.locale countryOS9];
53-
//XCTAssert([expected isEqualToString:actual]);
54-
5550
actual = [self.locale countryOS8];
5651
XCTAssert([expected isEqualToString:actual]);
5752
}

Branch-SDK/Branch-SDK/BNCDeviceInfo.h

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,56 @@
88

99
#if __has_feature(modules)
1010
@import Foundation;
11-
@import CoreGraphics;
1211
#else
1312
#import <Foundation/Foundation.h>
14-
#import <CoreGraphics/CoreGraphics.h>
1513
#endif
1614

1715
@interface BNCDeviceInfo : NSObject
1816

1917
+ (BNCDeviceInfo *)getInstance;
2018

19+
- (void)registerPluginName:(NSString *)name version:(NSString *)version;
20+
21+
- (NSDictionary *) v2dictionary;
22+
23+
/*
24+
Everything below this line should be private.
25+
Currently BNCServerInterface updateDeviceInfoToMutableDictionary uses it.
26+
*/
27+
28+
- (void)checkAdvertisingIdentifier;
29+
2130
@property (nonatomic, copy, readwrite) NSString *hardwareId;
2231
@property (nonatomic, copy, readwrite) NSString *hardwareIdType;
2332
@property (nonatomic, assign, readwrite) BOOL isRealHardwareId;
33+
34+
@property (nonatomic, copy, readwrite) NSString *advertiserId;
35+
@property (nonatomic, copy, readwrite) NSString *vendorId;
36+
@property (nonatomic, assign, readwrite) BOOL isAdTrackingEnabled;
37+
@property (nonatomic, assign, readwrite) BOOL unidentifiedDevice;
38+
- (NSString *)localIPAddress;
39+
- (NSString *)connectionType;
40+
2441
@property (nonatomic, copy, readwrite) NSString *brandName;
2542
@property (nonatomic, copy, readwrite) NSString *modelName;
2643
@property (nonatomic, copy, readwrite) NSString *osName;
2744
@property (nonatomic, copy, readwrite) NSString *osVersion;
45+
@property (nonatomic, copy, readwrite) NSString *osBuildVersion;
46+
@property (nonatomic, copy, readwrite) NSString *extensionType;
47+
@property (nonatomic, copy, readwrite) NSNumber *cpuType;
2848
@property (nonatomic, copy, readwrite) NSNumber *screenWidth;
2949
@property (nonatomic, copy, readwrite) NSNumber *screenHeight;
30-
@property (nonatomic, assign, readwrite) BOOL isAdTrackingEnabled;
31-
32-
@property (nonatomic, copy, readwrite) NSString *extensionType;
33-
@property (nonatomic, copy, readwrite) NSString *branchSDKVersion;
34-
@property (nonatomic, copy, readwrite) NSString *applicationVersion;
35-
@property (nonatomic, assign, readwrite) CGFloat screenScale;
36-
@property (nonatomic, copy, readwrite) NSString *adId;
37-
@property (nonatomic, assign, readwrite) BOOL unidentifiedDevice;
38-
50+
@property (nonatomic, copy, readwrite) NSNumber *screenScale;
51+
@property (nonatomic, copy, readwrite) NSString *carrierName;
52+
@property (nonatomic, copy, readwrite) NSString *locale;
3953
@property (nonatomic, copy, readwrite) NSString *country; //!< The iso2 Country name (us, in,etc).
4054
@property (nonatomic, copy, readwrite) NSString *language; //!< The iso2 language code (en, ml).
55+
- (NSString *)userAgentString;
4156

42-
@property (nonatomic, strong, readwrite) NSString *pluginName;
43-
@property (nonatomic, strong, readwrite) NSString *pluginVersion;
44-
45-
+ (NSString *)localIPAddress;
46-
+ (NSString *)vendorId;
47-
+ (NSString *)userAgentString;
57+
@property (nonatomic, copy, readwrite) NSString *applicationVersion;
58+
@property (nonatomic, copy, readwrite) NSString *pluginName;
59+
@property (nonatomic, copy, readwrite) NSString *pluginVersion;
60+
@property (nonatomic, copy, readwrite) NSString *branchSDKVersion;
4861

49-
- (NSDictionary *) v2dictionary;
5062

5163
@end

0 commit comments

Comments
 (0)