gpt4 book ai didi

ios - 在 iOS 上最小化 cordova 应用程序后 EAAccessory 停止

转载 作者:行者123 更新时间:2023-11-29 12:09:23 28 4
gpt4 key购买 nike

我正在构建一个连接到蓝牙阅读器的 cordova 应用程序。当应用程序运行时(未最小化)一切正常。我能够读取蓝牙数据。如果我现在最小化应用程序然后再次最大化它(不确定这是否是正确的术语),那么我将无法再接收任何数据。我确实在 XCode 中看到以下内容:

2015-11-26 12:24:13.944 MyAppName[704:170849] /SourceCache/ExternalAccessory/ExternalAccessory-288.20.7/EAAccessoryManager.m:__51-[EAAccessoryManager _checkForConnectedAccessories]_block_invoke-631 ending background task

我还尝试使用下面的代码实现 accessoryDidConnect 和 accessoryDidDisconnect,但是这两个函数都没有被调用:

- (void) pluginInitialize
{
NSLog(@"init called");
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(accessoryDidConnect:)
name:EAAccessoryDidConnectNotification
object:nil];


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessoryDidDisconnect:)
name:EAAccessoryDidDisconnectNotification object:nil];
}

-(void) accessoryDidConnect:(NSNotification *)notification
{
EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey];
NSLog(@"error :%@", connectedAccessory.protocolStrings);
// Only notify of change if the accessory added has valid protocol strings
if( connectedAccessory.protocolStrings.count != 0 )
{
_accessoryList = [[[EAAccessoryManager sharedAccessoryManager] connectedAccessories] mutableCopy];
}
NSLog(@"connected");
isDeviceLoaded=true;
}

- (void)accessoryDidDisconnect:(NSNotification *)notification
{
// EAAccessory *disconnectedAccessory = (EAAccessory *)[notification.userInfo objectForKey:@"EAAccessorySelectedKey"];
NSLog(@"disconnected");
_accessoryList = [[[EAAccessoryManager sharedAccessoryManager] connectedAccessories]mutableCopy];
isDeviceLoaded=true;
}

调用了 pluginInitialize 函数,但从未调用 accessoryDidConnect 或 accessoryDidDisconnect。如何重新连接到蓝牙阅读器?

最佳答案

我成功了。我的插件中缺少以下最后一行:

[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];

这里是完整的方法:

- (void) pluginInitialize
{
NSLog(@"init called");
[[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];

}

关于ios - 在 iOS 上最小化 cordova 应用程序后 EAAccessory 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33944452/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com