How can I programmatically get the MAC address of an iphone
NOTE As of iOS7, you can no longer retrieve device MAC addresses. A fixed value will be returned rather than the actual MAC
Somthing I stumbled across a while ago. Originally from here I modified it a bit and cleaned things up.
IPAddress.h
IPAddress.c
And to use it
InitAddresses();
GetIPAddresses();
GetHWAddresses();
int i;
NSString *deviceIP = nil;
for (i=0; i<MAXADDRS; ++i)
{
static unsigned long localHost = 0x7F000001; // 127.0.0.1
unsigned long theAddr;
theAddr = ip_addrs[i];
if (theAddr == 0) break;
if (theAddr == localHost) continue;
NSLog(@"Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]);
//decided what adapter you want details for
if (strncmp(if_names[i], "en", 2) == 0)
{
NSLog(@"Adapter en has a IP of %s", ip_names[i]);
}
}
Adapter names vary depending on the simulator/device as well as wifi or cell on the device.
How to get MAC address programmatically in my iOS app
Mac address is unavailable from ios 7 and up.
Apple Said
In iOS 7 and later, if you ask for the MAC address of an iOS device,
the system returns the value 02:00:00:00:00:00. If you need to
identify the device, use the identifierForVendor property of UIDevice
instead. (Apps that need an identifier for their own advertising
purposes should consider using the advertisingIdentifier property of
ASIdentifierManager instead.)
Check bottom of the page into Apple Document.
So better solution for that.
Following code returns unique address.
#import "UIDevice+Identifier.h"
- (NSString *) identifierForVendor1
{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return @"";
}
Calling Method
NSString *like_UDID=[NSString stringWithFormat:@"%@",
[[UIDevice currentDevice] identifierForVendor1]];
NSLog(@"%@",like_UDID);
Also another solution visit HERE
Edited
UIDevice+Identifier.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIDevice (IdentifierAddition)
- (NSString *) identifierForVendor1;
@end
UIDevice+Identifier.m
#import "UIDevice+Identifier.h"
@implementation UIDevice (IdentifierAddition)
- (NSString *) identifierForVendor1
{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return @"";
}
@end
Calling above Function.
ViewController.m
#import "ViewController.h"
#import "UIDevice+Identifier.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *like_UDID=[NSString stringWithFormat:@"%@",
[[UIDevice currentDevice] identifierForVendor1]];
NSLog(@"%@",like_UDID);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
How to get the wifi mac address on iPhone in Swift?
When you request the Device MAC address in iOS 7 and above you will always get the same response: 02:00:00:00:00:00, this has been made by Apple for privacy concerns.
In iOS 7 and later, if you ask for the MAC address of an iOS device, the system returns the value 02:00:00:00:00:00. If you need to identify the device, use the identifierForVendor property of UIDevice instead. (Apps that need an identifier for their own advertising purposes should consider using the advertisingIdentifier property of ASIdentifierManager instead.)
Apple recommends to switch to UDID
instead if you need to uniquely identify an iOS device. In Swift
you can use this:
UIDevice.currentDevice().identifierForVendor
if you want a string instead use:
UIDevice.currentDevice().identifierForVendor.UUIDString
Here's a nice reading about UDID
How can I programmatically get the Bluetooth MAC address of an iPhone?
There is no public API to get this information.
If this is an internal or jailbreak application you can get the value of the kLockdownBluetoothAddressKey
key via liblockdown.dylib
How can I programmatically get the MAC address of an iphone
NOTE As of iOS7, you can no longer retrieve device MAC addresses. A fixed value will be returned rather than the actual MAC
Somthing I stumbled across a while ago. Originally from here I modified it a bit and cleaned things up.
IPAddress.h
IPAddress.c
And to use it
InitAddresses();
GetIPAddresses();
GetHWAddresses();
int i;
NSString *deviceIP = nil;
for (i=0; i<MAXADDRS; ++i)
{
static unsigned long localHost = 0x7F000001; // 127.0.0.1
unsigned long theAddr;
theAddr = ip_addrs[i];
if (theAddr == 0) break;
if (theAddr == localHost) continue;
NSLog(@"Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]);
//decided what adapter you want details for
if (strncmp(if_names[i], "en", 2) == 0)
{
NSLog(@"Adapter en has a IP of %s", ip_names[i]);
}
}
Adapter names vary depending on the simulator/device as well as wifi or cell on the device.
Related Topics
Split a String into an Array in Swift
How to Set Cornerradius For Only Top-Left and Top-Right Corner of a Uiview
Uiview With Rounded Corners and Drop Shadow
Fatal Error: Unexpectedly Found Nil While Unwrapping an Optional Values
How to Create Dispatch Queue in Swift 3
Any Way to Pre Populate Core Data
Getting a Thumbnail from a Video Url or Data in Ios
How to Produce an Effect Similar to the iOS 7 Blur View
Will iOS Launch My App into the Background If It Was Force-Quit by the User
Uicollectionview Self Sizing Cells With Auto Layout
Getting Current Device Language in Ios
Nsfilemanager.Defaultmanager().Fileexistsatpath Returns False Instead of True
How to Make a Simple Collection View With Swift
How to Resize the Uiimage to Reduce Upload Image Size
How to Opt-Out of Dark Mode on iOS 13
Design For Facebook Authentication in an iOS App That Also Accesses a Secured Web Service