Skip to content

Commit 4923167

Browse files
authored
Made a fix for device country code crash. Enabled on on-device unit testing for iOS 7. (#647)
1 parent 12ca4d3 commit 4923167

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

Branch-SDK/Branch-SDK/BNCDeviceInfo.m

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ @interface BNCDeviceInfo()
2323

2424
@implementation BNCDeviceInfo
2525

26-
static BNCDeviceInfo *bncDeviceInfo;
27-
2826
+ (BNCDeviceInfo *)getInstance {
29-
if (!bncDeviceInfo) {
30-
bncDeviceInfo = [[BNCDeviceInfo alloc] init];
31-
}
32-
return bncDeviceInfo;
27+
static BNCDeviceInfo *bnc_deviceInfo = 0;
28+
static dispatch_once_t onceToken;
29+
dispatch_once(&onceToken, ^{
30+
bnc_deviceInfo = [[BNCDeviceInfo alloc] init];
31+
});
32+
return bnc_deviceInfo;
3333
}
3434

3535
- (id)init {
@@ -58,31 +58,31 @@ - (id)init {
5858
self.screenHeight = [BNCSystemObserver getScreenHeight];
5959
self.isAdTrackingEnabled = [BNCSystemObserver adTrackingSafe];
6060

61-
// Get the locale info --
62-
CGFloat systemVersion = [UIDevice currentDevice].systemVersion.floatValue;
63-
if (systemVersion < 9.0) {
61+
NSLocale *currentLocale = [NSLocale currentLocale];
62+
if ([currentLocale respondsToSelector:@selector(countryCode)] &&
63+
[currentLocale respondsToSelector:@selector(languageCode)]) {
64+
// Should work on iOS 10
65+
self.country = [currentLocale countryCode];
66+
self.language = [currentLocale languageCode];
67+
}
68+
69+
if (!self.country) {
70+
// Should work on iOS 9
71+
NSString *rawLanguage = [[NSLocale preferredLanguages] firstObject];
72+
NSDictionary *languageDictionary = [NSLocale componentsFromLocaleIdentifier:rawLanguage];
73+
self.country = [languageDictionary objectForKey:@"kCFLocaleCountryCodeKey"];
74+
self.language = [languageDictionary objectForKey:@"kCFLocaleLanguageCodeKey"];
75+
}
6476

77+
if (!self.country) {
78+
// Should work on iOS 8 and below.
6579
self.language = [[NSLocale preferredLanguages] firstObject];
66-
NSString *rawLocale = [NSLocale currentLocale].localeIdentifier;
80+
NSString *rawLocale = currentLocale.localeIdentifier;
6781
NSRange range = [rawLocale rangeOfString:@"_"];
6882
if (range.location != NSNotFound) {
6983
range = NSMakeRange(range.location+1, rawLocale.length-range.location-1);
7084
self.country = [rawLocale substringWithRange:range];
7185
}
72-
73-
} else if (systemVersion < 10.0) {
74-
75-
NSString *rawLanguage = [[NSLocale preferredLanguages] firstObject];
76-
NSDictionary *languageDictionary = [NSLocale componentsFromLocaleIdentifier:rawLanguage];
77-
self.country = [languageDictionary objectForKey:@"kCFLocaleCountryCodeKey"];
78-
self.language = [languageDictionary objectForKey:@"kCFLocaleLanguageCodeKey"];
79-
80-
} else {
81-
82-
NSLocale *locale = [NSLocale currentLocale];
83-
self.country = [locale countryCode];
84-
self.language = [locale languageCode ];
85-
8686
}
8787

8888
self.browserUserAgent = [self.class userAgentString];

Branch-TestBed-Xcode-7/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@
163163
remoteGlobalIDString = 466B58371B17773000A69EDE;
164164
remoteInfo = Branch;
165165
};
166+
4DED9ECE1F032EDD0033A6C3 /* PBXContainerItemProxy */ = {
167+
isa = PBXContainerItemProxy;
168+
containerPortal = 670016581940F51400A9E103 /* Project object */;
169+
proxyType = 1;
170+
remoteGlobalIDString = 6700165F1940F51400A9E103;
171+
remoteInfo = "Branch-TestBed";
172+
};
166173
/* End PBXContainerItemProxy section */
167174

168175
/* Begin PBXFileReference section */
@@ -745,6 +752,7 @@
745752
);
746753
dependencies = (
747754
4683F07C1B20AC6300A432E7 /* PBXTargetDependency */,
755+
4DED9ECF1F032EDD0033A6C3 /* PBXTargetDependency */,
748756
);
749757
name = "Branch-SDK-Tests";
750758
productName = "Branch-SDK Functionality Tests";
@@ -777,6 +785,7 @@
777785
7E6B3B501AA42D0E005F45BF = {
778786
CreatedOnToolsVersion = 6.1.1;
779787
DevelopmentTeam = R63EM248DP;
788+
TestTargetID = 6700165F1940F51400A9E103;
780789
};
781790
};
782791
};
@@ -851,7 +860,7 @@
851860
);
852861
runOnlyForDeploymentPostprocessing = 0;
853862
shellPath = /bin/sh;
854-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
863+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
855864
showEnvVarsInLog = 0;
856865
};
857866
CA6C45DB44005B39B2D6B322 /* [CP] Embed Pods Frameworks */ = {
@@ -982,6 +991,11 @@
982991
target = 466B58371B17773000A69EDE /* Branch */;
983992
targetProxy = 4683F07B1B20AC6300A432E7 /* PBXContainerItemProxy */;
984993
};
994+
4DED9ECF1F032EDD0033A6C3 /* PBXTargetDependency */ = {
995+
isa = PBXTargetDependency;
996+
target = 6700165F1940F51400A9E103 /* Branch-TestBed */;
997+
targetProxy = 4DED9ECE1F032EDD0033A6C3 /* PBXContainerItemProxy */;
998+
};
985999
/* End PBXTargetDependency section */
9861000

9871001
/* Begin PBXVariantGroup section */
@@ -1144,7 +1158,7 @@
11441158
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.sdk.Branch-TestBed";
11451159
PRODUCT_NAME = "$(TARGET_NAME)";
11461160
PROVISIONING_PROFILE = "";
1147-
USER_HEADER_SEARCH_PATHS = $PROJECT_DIR;
1161+
USER_HEADER_SEARCH_PATHS = "$PROJECT_DIR";
11481162
WRAPPER_EXTENSION = app;
11491163
};
11501164
name = Debug;
@@ -1165,7 +1179,7 @@
11651179
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.sdk.Branch-TestBed";
11661180
PRODUCT_NAME = "$(TARGET_NAME)";
11671181
PROVISIONING_PROFILE = "";
1168-
USER_HEADER_SEARCH_PATHS = $PROJECT_DIR;
1182+
USER_HEADER_SEARCH_PATHS = "$PROJECT_DIR";
11691183
WRAPPER_EXTENSION = app;
11701184
};
11711185
name = Release;
@@ -1185,6 +1199,7 @@
11851199
MTL_ENABLE_DEBUG_INFO = YES;
11861200
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.sdk.$(PRODUCT_NAME:rfc1034identifier)";
11871201
PRODUCT_NAME = "$(TARGET_NAME)";
1202+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Branch-TestBed.app/Branch-TestBed";
11881203
};
11891204
name = Debug;
11901205
};
@@ -1199,6 +1214,7 @@
11991214
MTL_ENABLE_DEBUG_INFO = NO;
12001215
PRODUCT_BUNDLE_IDENTIFIER = "io.branch.sdk.$(PRODUCT_NAME:rfc1034identifier)";
12011216
PRODUCT_NAME = "$(TARGET_NAME)";
1217+
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Branch-TestBed.app/Branch-TestBed";
12021218
};
12031219
name = Release;
12041220
};

0 commit comments

Comments
 (0)