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
0a374b58
Commit
0a374b58
authored
Nov 09, 2017
by
Naoto Ida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added iOS/Android support for getting carrier information
parent
589633a9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
18 deletions
+41
-18
README.md
README.md
+1
-1
RNDeviceInfo.m
RNDeviceInfo/RNDeviceInfo.m
+10
-0
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+7
-0
deviceinfo.d.ts
deviceinfo.d.ts
+1
-0
deviceinfo.js
deviceinfo.js
+20
-17
deviceinfo.js.flow
deviceinfo.js.flow
+1
-0
RNDeviceInfoModule.cs
windows/RNDeviceInfo/RNDeviceInfoModule.cs
+1
-0
No files found.
README.md
View file @
0a374b58
...
...
@@ -193,7 +193,7 @@ var DeviceInfo = require('react-native-device-info');
| Serial Number | `
getSerialNumber()
` | `
string
` | Only supported in Android
| IP Address | `
getIPAddress()
` | `
Promise
<string>
` | Only supported in Android
| MAC Address | `
getMACAddress()
` | `
Promise
<string>
` | Only supported in Android
| Carrier | `
getCarrier()
` | `
string
` e.g. "SOFTBANK" | | |
Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript:
```js
...
...
RNDeviceInfo/RNDeviceInfo.m
View file @
0a374b58
...
...
@@ -14,6 +14,8 @@
@property
(
nonatomic
)
bool
isEmulator
;
@end
@import
CoreTelephony
;
@implementation
RNDeviceInfo
@synthesize
isEmulator
;
...
...
@@ -150,6 +152,13 @@ RCT_EXPORT_MODULE()
return
deviceName
;
}
-
(
NSString
*
)
carrier
{
CTTelephonyNetworkInfo
*
netinfo
=
[[
CTTelephonyNetworkInfo
alloc
]
init
];
CTCarrier
*
carrier
=
[
netinfo
subscriberCellularProvider
];
return
carrier
.
carrierName
;
}
-
(
NSString
*
)
userAgent
{
#if TARGET_OS_TV
...
...
@@ -204,6 +213,7 @@ RCT_EXPORT_MODULE()
@"appVersion"
:
[[
NSBundle
mainBundle
]
objectForInfoDictionaryKey
:
@"CFBundleShortVersionString"
]
?:
[
NSNull
null
],
@"buildNumber"
:
[[
NSBundle
mainBundle
]
objectForInfoDictionaryKey
:
@"CFBundleVersion"
],
@"systemManufacturer"
:
@"Apple"
,
@"carrier"
:
self
.
carrier
?:
[
NSNull
null
],
@"userAgent"
:
self
.
userAgent
,
@"timezone"
:
self
.
timezone
,
@"isEmulator"
:
@
(
self
.
isEmulator
),
...
...
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
0a374b58
...
...
@@ -107,6 +107,12 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
p
.
resolve
(
macAddress
);
}
@ReactMethod
public
String
getCarrier
()
{
TelephonyManager
telMgr
=
(
TelephonyManager
)
this
.
reactContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
return
telMgr
.
getNetworkOperatorName
();
}
@Override
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
HashMap
<
String
,
Object
>
constants
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -172,6 +178,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
TelephonyManager
telMgr
=
(
TelephonyManager
)
this
.
reactContext
.
getApplicationContext
().
getSystemService
(
Context
.
TELEPHONY_SERVICE
);
constants
.
put
(
"phoneNumber"
,
telMgr
.
getLine1Number
());
}
constants
.
put
(
"carrier"
,
this
.
getCarrier
());
return
constants
;
}
}
deviceinfo.d.ts
View file @
0a374b58
...
...
@@ -28,3 +28,4 @@ export function getIPAddress(): Promise<string>;
export
function
getMACAddress
():
Promise
<
string
>
;
export
function
getPhoneNumber
():
string
;
export
function
getAPILevel
():
number
;
export
function
getCarrier
():
string
;
deviceinfo.js
View file @
0a374b58
...
...
@@ -5,40 +5,40 @@
var
RNDeviceInfo
=
require
(
'react-native'
).
NativeModules
.
RNDeviceInfo
;
module
.
exports
=
{
getUniqueID
:
function
()
{
getUniqueID
:
function
()
{
return
RNDeviceInfo
.
uniqueId
;
},
getInstanceID
:
function
()
{
return
RNDeviceInfo
.
instanceId
;
},
getSerialNumber
:
function
()
{
getSerialNumber
:
function
()
{
return
RNDeviceInfo
.
serialNumber
;
},
getIPAddress
:
function
()
{
getIPAddress
:
function
()
{
return
RNDeviceInfo
.
getIpAddress
();
},
getMACAddress
:
function
()
{
getMACAddress
:
function
()
{
return
RNDeviceInfo
.
getMacAddress
();
},
getDeviceId
:
function
()
{
getDeviceId
:
function
()
{
return
RNDeviceInfo
.
deviceId
;
},
getManufacturer
:
function
()
{
getManufacturer
:
function
()
{
return
RNDeviceInfo
.
systemManufacturer
;
},
getModel
:
function
()
{
getModel
:
function
()
{
return
RNDeviceInfo
.
model
;
},
getBrand
:
function
()
{
getBrand
:
function
()
{
return
RNDeviceInfo
.
brand
;
},
getSystemName
:
function
()
{
getSystemName
:
function
()
{
return
RNDeviceInfo
.
systemName
;
},
getSystemVersion
:
function
()
{
getSystemVersion
:
function
()
{
return
RNDeviceInfo
.
systemVersion
;
},
getAPILevel
:
function
()
{
getAPILevel
:
function
()
{
return
RNDeviceInfo
.
apiLevel
;
},
getBundleId
:
function
()
{
...
...
@@ -51,7 +51,7 @@ module.exports = {
return
RNDeviceInfo
.
appVersion
;
},
getReadableVersion
:
function
()
{
return
RNDeviceInfo
.
appVersion
+
"."
+
RNDeviceInfo
.
buildNumber
;
return
RNDeviceInfo
.
appVersion
+
'.'
+
RNDeviceInfo
.
buildNumber
;
},
getDeviceName
:
function
()
{
return
RNDeviceInfo
.
deviceName
;
...
...
@@ -74,16 +74,19 @@ module.exports = {
isTablet
:
function
()
{
return
RNDeviceInfo
.
isTablet
;
},
isPinOrFingerprintSet
:
function
()
{
isPinOrFingerprintSet
:
function
()
{
return
RNDeviceInfo
.
isPinOrFingerprintSet
;
},
getFirstInstallTime
:
function
()
{
getFirstInstallTime
:
function
()
{
return
RNDeviceInfo
.
firstInstallTime
;
},
getLastUpdateTime
:
function
()
{
getLastUpdateTime
:
function
()
{
return
RNDeviceInfo
.
lastUpdateTime
;
},
getPhoneNumber
:
function
()
{
getPhoneNumber
:
function
()
{
return
RNDeviceInfo
.
phoneNumber
;
}
},
getCarrier
:
function
()
{
return
RNDeviceInfo
.
carrier
;
},
};
deviceinfo.js.flow
View file @
0a374b58
...
...
@@ -28,4 +28,5 @@ declare module.exports: {
getSerialNumber: () => string,
getIPAddress: () => Promise<string>,
getMACAddress: () => Promise<string>,
getCarrier: () => string,
}
windows/RNDeviceInfo/RNDeviceInfoModule.cs
View file @
0a374b58
...
...
@@ -112,6 +112,7 @@ namespace RNDeviceInfo
constants
[
"timezone"
]
=
TimeZoneInfo
.
Local
.
Id
;
constants
[
"isEmulator"
]
=
IsEmulator
(
model
);
constants
[
"isTablet"
]
=
IsTablet
(
os
);
constants
[
"carrier"
]
=
"not available"
;
return
constants
;
}
...
...
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