nsnotificationcenter - 当应用程序处于后台时获取 EAAccessoryDidConnectNotification (iOS)

标签 nsnotificationcenter eaaccessory

在我的“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/

相关文章:

ios - 移除 NSNotificationCenter 观察者

iphone - 通过通知执行选择器OnMainThread

swift - 从后台获取 NSObjects 时应用程序崩溃

ios - 如何测试 EADemo 蓝牙应用程序

ios - 如何在不连接到真正的蓝牙设备的情况下创建 `EAAccessory` 对象?

swift - 快速获取 eaaccessory macaddress

ios - UIDeviceOrientation DidChange 仅适用于 iPhone 7

objective-c - 用户清空垃圾时通知?

ios - 我可以同时将一个 MFI 配件与两个应用程序连接吗