问题描述
我有一个班级来管理来自和转到iPad的外部附件的消息。在init中我有以下代码:
I have a class that manages messages coming from and going to an external accessory to an iPad. In the init I have the following code:
- (id) init
{
self = [super init];
if (!self) return;
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications]; //we want to hear about accessories connecting and disconnecting
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessoryDidConnect:)
name:EAAccessoryDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessoryDidDisconnect:)
name:EAAccessoryDidDisconnectNotification
object:nil];
...
}
在dealloc我有
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidDisconnectNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidConnectNotification object:nil];
[[EAAccessoryManager sharedAccessoryManager] unregisterForLocalNotifications];
}
出于某种原因,当我将外部配件连接到iPad时,accessoryDidConnect:火灾后跟一个accessoryDidDisconnect:然后是accessoryDidConnect:
For some reason, when I connect the external accessory to the iPad the accessoryDidConnect: fires followed by an accessoryDidDisconnect: followed by accessoryDidConnect:
我无法弄清楚为什么我会得到额外的连接和断开连接。任何想法?
I can't figure out why I would get an extra connect and disconnect. Any ideas?
推荐答案
eaaccessory框架将始终从某种原因触发2个连接和2个断开连接通知。第一个连接断开线对没有协议字符串,你可以忽略它们。
the eaaccessory framework will always fire 2 connect and 2 disconnect notifications from some reason. The first connect disconnect pair will have no protocol strings, you can ignore these.
这篇关于为什么EAAccessoryDidConnectNotification会发生两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!