Commit 818bc6a7 authored by Rebecca Hughes's avatar Rebecca Hughes

Merge pull request #30 from mikefowler/master

Add support for device country
parents 033e7370 09cc01de
...@@ -132,6 +132,12 @@ RCT_EXPORT_MODULE() ...@@ -132,6 +132,12 @@ RCT_EXPORT_MODULE()
return language; return language;
} }
- (NSString*) deviceCountry
{
NSString *country = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
return country;
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
...@@ -146,6 +152,7 @@ RCT_EXPORT_MODULE() ...@@ -146,6 +152,7 @@ RCT_EXPORT_MODULE()
@"deviceId": self.deviceId, @"deviceId": self.deviceId,
@"deviceName": currentDevice.name, @"deviceName": currentDevice.name,
@"deviceLocale": self.deviceLocale, @"deviceLocale": self.deviceLocale,
@"deviceCountry": self.deviceCountry,
@"uniqueId": uniqueId, @"uniqueId": uniqueId,
@"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"], @"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"],
@"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
...@@ -156,4 +163,3 @@ RCT_EXPORT_MODULE() ...@@ -156,4 +163,3 @@ RCT_EXPORT_MODULE()
} }
@end @end
...@@ -44,6 +44,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -44,6 +44,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
} }
} }
private String getCurrentCountry() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
return current.getCountry();
}
@Override @Override
public @Nullable Map<String, Object> getConstants() { public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>(); HashMap<String, Object> constants = new HashMap<String, Object>();
...@@ -77,6 +82,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -77,6 +82,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("model", Build.MODEL); constants.put("model", Build.MODEL);
constants.put("deviceId", Build.BOARD); constants.put("deviceId", Build.BOARD);
constants.put("deviceLocale", this.getCurrentLanguage()); constants.put("deviceLocale", this.getCurrentLanguage());
constants.put("deviceCountry", this.getCurrentCountry());
constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID)); constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID));
constants.put("systemManufacturer", Build.MANUFACTURER); constants.put("systemManufacturer", Build.MANUFACTURER);
constants.put("bundleId", packageName); constants.put("bundleId", packageName);
......
...@@ -43,5 +43,8 @@ module.exports = { ...@@ -43,5 +43,8 @@ module.exports = {
}, },
getDeviceLocale: function() { getDeviceLocale: function() {
return RNDeviceInfo.deviceLocale; return RNDeviceInfo.deviceLocale;
} },
getDeviceCountry: function() {
return RNDeviceInfo.deviceCountry;
},
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment