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
41735bd0
Commit
41735bd0
authored
Jul 23, 2018
by
Mehdi Achour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ios): Add getIpAddress & getMacAddress
parent
3d45ba54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
RNDeviceInfo.m
ios/RNDeviceInfo/RNDeviceInfo.m
+38
-0
No files found.
ios/RNDeviceInfo/RNDeviceInfo.m
View file @
41735bd0
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
// Copyright © 2015 Learnium Limited. All rights reserved.
// Copyright © 2015 Learnium Limited. All rights reserved.
//
//
#include <ifaddrs.h>
#include <arpa/inet.h>
#import "RNDeviceInfo.h"
#import "RNDeviceInfo.h"
#import "DeviceUID.h"
#import "DeviceUID.h"
#if !(TARGET_OS_TV)
#if !(TARGET_OS_TV)
...
@@ -293,6 +295,42 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
...
@@ -293,6 +295,42 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
};
};
}
}
RCT_EXPORT_METHOD
(
getMacAddress
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
NSString
*
address
=
@"02:00:00:00:00:00"
;
resolve
(
address
);
}
RCT_EXPORT_METHOD
(
getIpAddress
:
(
RCTPromiseResolveBlock
)
resolve
rejecter
:
(
RCTPromiseRejectBlock
)
reject
)
{
NSString
*
address
=
@"0.0.0.0"
;
struct
ifaddrs
*
interfaces
=
NULL
;
struct
ifaddrs
*
temp_addr
=
NULL
;
int
success
=
0
;
// retrieve the current interfaces - returns 0 on success
success
=
getifaddrs
(
&
interfaces
);
if
(
success
==
0
)
{
// Loop through linked list of interfaces
temp_addr
=
interfaces
;
while
(
temp_addr
!=
NULL
)
{
if
(
temp_addr
->
ifa_addr
->
sa_family
==
AF_INET
)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if
([[
NSString
stringWithUTF8String
:
temp_addr
->
ifa_name
]
isEqualToString
:
@"en0"
])
{
// Get NSString from C String
address
=
[
NSString
stringWithUTF8String
:
inet_ntoa
(((
struct
sockaddr_in
*
)
temp_addr
->
ifa_addr
)
->
sin_addr
)];
}
}
temp_addr
=
temp_addr
->
ifa_next
;
}
}
// Free memory
freeifaddrs
(
interfaces
);
resolve
(
address
);
}
RCT_EXPORT_METHOD
(
isPinOrFingerprintSet
:
(
RCTResponseSenderBlock
)
callback
)
RCT_EXPORT_METHOD
(
isPinOrFingerprintSet
:
(
RCTResponseSenderBlock
)
callback
)
{
{
#if TARGET_OS_TV
#if TARGET_OS_TV
...
...
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