我之前要说对不起,我的英语不好。
我正在开发一个与"外部配件框架相关的项目"。 我需要从我们的产品中获取一些数据流,通过" USB到闪电"适配器。 我好几天都在转动轮子。
我的问题是"使用框架的确切方法"。 我在apple dev论坛上找到了一些东西: pic
这是否意味着如果我有一个" USB闪电"适配器及其协议字符串(目前,我们不打算制作我们自己的适配器,我们计划与其他公司合作),然后我将产品插入其中,我的应用程序将收到通知附件或删除配件。
我是对的吗?
我现在感到困惑,因为我的一位同事联系了一个适配器供应商,他们告诉她有 NO 这样的事情叫做"协议字符串"。 我想由于某些原因他们不想让我们知道。
谢谢!
答案 0 :(得分:0)
You have set up these notifications for connection. Make you make connection through BT or USB.
/* Setup notification monitor */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAccessoryConnectNotification:) name:EAAccessoryDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAccessoryDisconnectNotification:) name:EAAccessoryDidDisconnectNotification object:nil];
/* Turn on EA notifications */
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
Once connection establishes you will get a call back with accessory info.
- (void) handleAccessoryConnectNotification:(NSNotification*)notification
{
NSDictonary *earInfo = notification.userInfo;
Print(@“Accessory Info: %@”,earInfo);
// Get connected Accessory object.
EAAccessory* currentAccessory = eaInfo[@"EAAccessoryKey"];
// Create Session with base Protocol with Accessory.
EASession* currentEASession = [[EASession alloc] initWithAccessory:currentAccessory forProtocol:“com.accessory.base”];
/* Open input and output steam */
if ( self.currentEASession.inputStream && self.currentEASession.outputStream)
{
[[currentEASession inputStream] setDelegate:self];
[[currentEASession inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[currentEASession inputStream] open];
[[currentEASession outputStream] setDelegate:self];
[[currentEASession outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[currentEASession outputStream] open];
}
}
- (void)handleAccessoryDisconnectNotification:(NSNotification*)notification {
Print(@“Accessory Info: %@”notification.userInfo);
}
# Read and Write data delegate method
- ( void ) stream: ( NSStream * ) aStream handleEvent: ( NSStreamEvent ) eventCode {
@try
{
switch ( eventCode )
{
case NSStreamEventOpenCompleted:{
Print(@“[%s] NSStreamEventOpenCompleted",__PRETTY_FUNCTION__);
break;
}
case NSStreamEventHasSpaceAvailable:
{
/* Write data */
break;
}
case NSStreamEventHasBytesAvailable:
{
//TODO
/* Read data */
static uint8_t buffer[65536];
NSInteger n = 65536;
while (n == 65536)
{
n = [self.currentEASession.inputStream read:buffer maxLength:65536];
}
break;
}
case NSStreamEventErrorOccurred:
{
//TODO
Print(@"[%s] NSStreamEventErrorOccurred",__PRETTY_FUNCTION__);
break;
}
case NSStreamEventEndEncountered:
{
//TODO
Print(@"[%s] NSStreamEventEndEncountered",__PRETTY_FUNCTION__);
break;
}
default:
{
break;
}
}
}
@catch (NSException *exception)
{
}
}
答案 1 :(得分:0)
外部附件与协议之间的关系是
将iOS设备与附件连接时。您必须在配件和iOS设备之间创建会话以读取和写入数据。协议字符串将标识附件和iOS设备之间用于共享和写入数据的唯一连接。
同一时间,一个附件可以与多个iOS设备连接。每个设备之间都将具有唯一的连接或会话,并将通过协议进行标识。