Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-device-info
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-device-info
Commits
09cc01de
Commit
09cc01de
authored
Mar 17, 2016
by
Mike Fowler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for device country
parent
f5b66d3b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
RNDeviceInfo.m
RNDeviceInfo/RNDeviceInfo.m
+14
-8
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+6
-0
deviceinfo.js
deviceinfo.js
+4
-1
No files found.
RNDeviceInfo/RNDeviceInfo.m
View file @
09cc01de
...
@@ -27,9 +27,9 @@ RCT_EXPORT_MODULE()
...
@@ -27,9 +27,9 @@ RCT_EXPORT_MODULE()
-
(
NSString
*
)
deviceId
-
(
NSString
*
)
deviceId
{
{
struct
utsname
systemInfo
;
struct
utsname
systemInfo
;
uname
(
&
systemInfo
);
uname
(
&
systemInfo
);
return
[
NSString
stringWithCString
:
systemInfo
.
machine
return
[
NSString
stringWithCString
:
systemInfo
.
machine
encoding
:
NSUTF8StringEncoding
];
encoding
:
NSUTF8StringEncoding
];
}
}
...
@@ -37,9 +37,9 @@ RCT_EXPORT_MODULE()
...
@@ -37,9 +37,9 @@ RCT_EXPORT_MODULE()
-
(
NSString
*
)
deviceName
-
(
NSString
*
)
deviceName
{
{
static
NSDictionary
*
deviceNamesByCode
=
nil
;
static
NSDictionary
*
deviceNamesByCode
=
nil
;
if
(
!
deviceNamesByCode
)
{
if
(
!
deviceNamesByCode
)
{
deviceNamesByCode
=
@{
@"i386"
:
@"Simulator"
,
deviceNamesByCode
=
@{
@"i386"
:
@"Simulator"
,
@"x86_64"
:
@"Simulator"
,
@"x86_64"
:
@"Simulator"
,
@"iPod1,1"
:
@"iPod Touch"
,
// (Original)
@"iPod1,1"
:
@"iPod Touch"
,
// (Original)
...
@@ -100,12 +100,12 @@ RCT_EXPORT_MODULE()
...
@@ -100,12 +100,12 @@ RCT_EXPORT_MODULE()
@"AppleTV5,3"
:
@"Apple TV"
,
// Apple TV (4th Generation)
@"AppleTV5,3"
:
@"Apple TV"
,
// Apple TV (4th Generation)
};
};
}
}
NSString
*
deviceName
=
[
deviceNamesByCode
objectForKey
:
self
.
deviceId
];
NSString
*
deviceName
=
[
deviceNamesByCode
objectForKey
:
self
.
deviceId
];
if
(
!
deviceName
)
{
if
(
!
deviceName
)
{
// Not found on database. At least guess main device type from string contents:
// Not found on database. At least guess main device type from string contents:
if
([
self
.
deviceId
rangeOfString
:
@"iPod"
].
location
!=
NSNotFound
)
{
if
([
self
.
deviceId
rangeOfString
:
@"iPod"
].
location
!=
NSNotFound
)
{
deviceName
=
@"iPod Touch"
;
deviceName
=
@"iPod Touch"
;
}
}
...
@@ -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
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
09cc01de
...
@@ -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
);
...
...
deviceinfo.js
View file @
09cc01de
...
@@ -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
;
},
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment