首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何知道所插入的是哪种设备?

问如何知道所插入的是哪种设备?
EN

Stack Overflow用户
提问于 2013-10-03 04:07:07
回答 1查看 318关注 0票数 1

我使用下面的代码来了解设备何时插入:

代码语言:javascript
复制
- (void)applicationDidBecomeActive:(UIApplication *)application 
{
     //code...

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accesoryChanged:) name:EAAccessoryDidConnectNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accesoryChanged:) name:EAAccessoryDidDisconnectNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accesoryChanged:) name:UIScreenDidConnectNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accesoryChanged:) name:UIScreenDidDisconnectNotification object:nil];

     EAAccessoryManager *accessoryManager = [EAAccessoryManager sharedAccessoryManager];
     [accessoryManager registerForLocalNotifications];
 }

- (void)accesoryChanged:(NSNotification*)note;
{
    if(note.name == EAAccessoryDidConnectNotification)
    {
        EAAccessory* accessory = [note.userInfo objectForKey:EAAccessoryKey];
        //code...
    }
    else if(note.name == EAAccessoryDidDisconnectNotification)
    {
        EAAccessory* accessory = [note.userInfo objectForKey:EAAccessoryKey];
        //code...
    }
}

并通过以下方式:

代码语言:javascript
复制
accessory.name

我可以得到设备的名称,但我找不到一种方法来知道设备的类型(例如:控制器或HDMI适配器)。

有什么方法可以获得这些信息吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-10-03 04:16:11

EAAccessory对象具有manufacturer、modelNumber和serialNumber的属性。您还可以查看protocolStrings数组以了解设备的功能。

在决定是否连接到附件时,您应该使用附件声明的协议来做出决定。与附件相关联的协议指示附件能够处理的数据类型。您可以使用其他属性来帮助您决定是否连接到附件,但协议列表应该是您考虑的关键因素。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19145904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档