在我的“viewDidLoad”
ViewController.m
中,我使用“EAAccessoryDidConnectNotification
”注册到 NSNotificationCenter defaultCenter
>' 和 'EAAccessoryDidDisconnectNotification
'
当我的应用程序在前台处于事件状态时,我会收到通知,并在accessoryDidConnect 中进行响应。一切正常。
但是,当应用程序在后台时,我怎样才能收到这样的通知?
('EAAccessoryDidConnectNotification' and 'EAAccessoryDidDisconnectNotification')
[Code below]
非常感谢。 丹
(void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessoryDidConnect:)
name:EAAccessoryDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessoryDidDisconnect:)
name:EAAccessoryDidDisconnectNotification
object:nil];
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
}
最佳答案
根据documentation ,这是不可能的:
If your app is suspended in the background when an accessory notification arrives, that notification is put in a queue. When your app begins running again (either in the foreground or background), notifications in the queue are delivered to your app. Notifications are also coalesced and filtered wherever possible to eliminate any irrelevant events. For example, if an accessory was connected and subsequently disconnected while your app was suspended, your app would ultimately not receive any indication that such events took place.
但如果有人证明我错了,那就很有趣了。
关于nsnotificationcenter - 当应用程序处于后台时获取 EAAccessoryDidConnectNotification (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15203940/