如何在我的iOS应用程序中以编程方式获取MAC地址

我是Objective-C的新手,实际上我想在设备连接到WiFi时显示mac地址,我已经看到很多关于这个的答案,但是我无法得到我想要的。 所以请任何人都可以引导我的forms的教程。 先谢谢你。

Mac地址是从ios 7及以上不可用。

苹果说

在iOS 7及更高版本中,如果您要求inputiOS设备的MAC地址,系统将返回值02:00:00:00:00:00。 如果您需要识别设备,请改用UIDevice的identifierForVendor属性。 (需要为自己的广告目的标识符的应用程序应考虑使用ASIdentifierManager的advertisingIdentifier属性。)

将页面底部检查到Apple文档中。

所以更好的解决scheme。 以下代码返回唯一地址。

#import "UIDevice+Identifier.h" - (NSString *) identifierForVendor1 { if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) { return [[[UIDevice currentDevice] identifierForVendor] UUIDString]; } return @""; } 

调用方法

 NSString *like_UDID=[NSString stringWithFormat:@"%@", [[UIDevice currentDevice] identifierForVendor1]]; NSLog(@"%@",like_UDID); 

另外一个解决scheme访问这里

编辑

的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 

调用上面的函数。

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