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
66ed41a8
Commit
66ed41a8
authored
Sep 20, 2017
by
Douglas Nassif Roma Junior
Committed by
GitHub
Sep 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from douglasjunior/patch-1
Added device detection even when in an iOS emulator.
parents
c362de2b
5f5fb2b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
+22
-15
RNDeviceInfo.m
RNDeviceInfo/RNDeviceInfo.m
+22
-15
No files found.
RNDeviceInfo/RNDeviceInfo.m
View file @
66ed41a8
...
...
@@ -11,7 +11,7 @@
#import <LocalAuthentication/LocalAuthentication.h>
@interface
RNDeviceInfo
()
@property
(
nonatomic
)
bool
isEmulator
;
@end
@implementation
RNDeviceInfo
...
...
@@ -19,6 +19,8 @@
}
@synthesize
isEmulator
;
RCT_EXPORT_MODULE
()
-
(
dispatch_queue_t
)
methodQueue
...
...
@@ -31,9 +33,18 @@ RCT_EXPORT_MODULE()
struct
utsname
systemInfo
;
uname
(
&
systemInfo
);
return
[
NSString
stringWithCString
:
systemInfo
.
machine
encoding
:
NSUTF8StringEncoding
];
NSString
*
deviceId
=
[
NSString
stringWithCString
:
systemInfo
.
machine
encoding
:
NSUTF8StringEncoding
];
if
([
deviceId
isEqualToString
:
@"i386"
]
||
[
deviceId
isEqualToString
:
@"x86_64"
]
)
{
deviceId
=
[
NSString
stringWithFormat
:
@"%s"
,
getenv
(
"SIMULATOR_MODEL_IDENTIFIER"
)];
self
.
isEmulator
=
YES
;
}
else
{
self
.
isEmulator
=
NO
;
}
return
deviceId
;
}
-
(
NSString
*
)
deviceName
...
...
@@ -41,10 +52,8 @@ RCT_EXPORT_MODULE()
static
NSDictionary
*
deviceNamesByCode
=
nil
;
if
(
!
deviceNamesByCode
)
{
deviceNamesByCode
=
@{
@"i386"
:
@"Simulator"
,
@"x86_64"
:
@"Simulator"
,
@"iPod1,1"
:
@"iPod Touch"
,
// (Original)
deviceNamesByCode
=
@{
@"iPod1,1"
:
@"iPod Touch"
,
// (Original)
@"iPod2,1"
:
@"iPod Touch"
,
// (Second Generation)
@"iPod3,1"
:
@"iPod Touch"
,
// (Third Generation)
@"iPod4,1"
:
@"iPod Touch"
,
// (Fourth Generation)
...
...
@@ -86,6 +95,9 @@ RCT_EXPORT_MODULE()
@"iPhone9,3"
:
@"iPhone 7"
,
// (model A1778 | Global)
@"iPhone9,2"
:
@"iPhone 7 Plus"
,
// (model A1661 | CDMA)
@"iPhone9,4"
:
@"iPhone 7 Plus"
,
// (model A1784 | Global)
@"iPhone10,3"
:
@"iPhone X"
,
//
@"iPhone10,4"
:
@"iPhone 8"
,
//
@"iPhone10,5"
:
@"iPhone 8 Plus"
,
//
@"iPad4,1"
:
@"iPad Air"
,
// 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2"
:
@"iPad Air"
,
// 5th Generation iPad (iPad Air) - Cellular
@"iPad4,3"
:
@"iPad Air"
,
// 5th Generation iPad (iPad Air)
...
...
@@ -143,8 +155,8 @@ RCT_EXPORT_MODULE()
-
(
NSString
*
)
deviceCountry
{
NSString
*
country
=
[[
NSLocale
currentLocale
]
objectForKey
:
NSLocaleCountryCode
];
return
country
;
NSString
*
country
=
[[
NSLocale
currentLocale
]
objectForKey
:
NSLocaleCountryCode
];
return
country
;
}
-
(
NSString
*
)
timezone
...
...
@@ -153,11 +165,6 @@ RCT_EXPORT_MODULE()
return
currentTimeZone
.
name
;
}
-
(
bool
)
isEmulator
{
return
[
self
.
deviceName
isEqual
:
@"Simulator"
];
}
-
(
bool
)
isTablet
{
return
[[
UIDevice
currentDevice
]
userInterfaceIdiom
]
==
UIUserInterfaceIdiomPad
;
...
...
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