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 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 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 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
Related Topics
Performance Testing in Swift Using Tdd
Autolayout + Rtl + Uilabel Text Alignment
Trigger Local Notifications Automatically Daily on Dynamic Time Given in Arrays Objective C iOS
Uitableviewcell Show White Background and Cannot Be Modified on iOS7
Immutable/Mutable Collections in Swift
Dealing with iPad Mini Screen Size
Wkwebview Open Links from Certain Domain in Safari
Sprite Moves Two Places After Being Paused and Then Unpaused
iOS 6 Facebook Posting Procedure Ends Up with "Remote_App_Id Does Not Match Stored Id"
Add Child View Controller to Current View Controller
Using Updatechildvalues to Delete from Firebase
How to Programmatically Fake a Touch Event to a Uibutton
Does Dispatch_Async(Dispatch_Get_Main_Queue(), ^{...}); Wait Until Done