2

I am new to Objective-C, actually I want to display mac address when my device is connected to WiFi and I have seen many answers regarding this but I am unable to get what I want. So please can anyone guide me in form of tutorial. Thank you in advance.

Jiri Tousek
  • 12,211
  • 5
  • 29
  • 43

1 Answers1

5

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
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72