Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS应用程序中以编程方式获取MAC地址_Ios_Objective C - Fatal编程技术网

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

如何在iOS应用程序中以编程方式获取MAC地址,ios,objective-c,Ios,Objective C,我是Objective-C新手,实际上我想在我的设备连接到WiFi时显示mac地址,我已经看到了很多关于这一点的答案,但我无法得到我想要的。所以,请任何人都可以指导我的形式的教程。先谢谢你 Mac地址在ios 7及更高版本中不可用 苹果说 在iOS 7及更高版本中,如果您询问iOS设备的MAC地址, 系统返回值02:00:00:00:00。如果你需要 标识设备,使用UIDevice的identifierForVendor属性 相反(需要自己的广告标识的应用程序) 目的应考虑使用广告标识符属性 请

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

Mac地址在ios 7及更高版本中不可用

苹果说

在iOS 7及更高版本中,如果您询问iOS设备的MAC地址, 系统返回值02:00:00:00:00。如果你需要 标识设备,使用UIDevice的identifierForVendor属性 相反(需要自己的广告标识的应用程序) 目的应考虑使用广告标识符属性 请改用身份识别器管理器。)

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

#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);

已编辑

UIDevice+标识符.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface UIDevice (IdentifierAddition)
- (NSString *) identifierForVendor1;
@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

试试这个@PrashantTukadiya我看到了你提供的链接,但我已经看过了,但是代码不起作用。我应该在NSObject类中添加此代码吗?不,你需要添加
UIDevice
class类。@BalajiPraveen我想你的问题现在解决了…[m:10:9:'UIDevice+Identifier.h'文件找不到]告诉我这个错误,你只需按照我上面编辑的答案。这可能会解决你的问题。
#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