深入探索iOS ExternalAccessory.framework框架

需积分: 26 2 下载量 59 浏览量 更新于2024-11-04 收藏 57KB ZIP 举报
资源摘要信息:"ExternalAccessory:研究 ExternalAccessory.framework" 在iOS开发中,ExternalAccessory.framework是一个用于与外部配件(附件)通信的框架。此框架为开发者提供了与外部配件进行数据交互的API,特别适合那些需要开发支持苹果MFi(Made for iPod/iPhone/iPad)计划配件的iOS应用程序。本篇文章将详细探讨如何研究和使用ExternalAccessory.framework,以期为开发者提供深入的理解和应用指导。 一、ExternalAccessory.framework概述 ExternalAccessory框架是iOS SDK中的一个组件,它使得应用程序可以与外部配件进行通信。这些配件可以是各种形式,例如医疗设备、乐器、打印机、健身器材等,只要它们遵循苹果的MFi标准并且获得官方授权。 外部配件通过外部总线,如蓝牙或USB(通过Lightning连接器)与iOS设备连接。ExternalAccessory.framework允许应用程序检测可用的配件、与配件通信以及发现配件支持的数据类型和服务。 二、使用Objective-C进行开发 在本示例中,我们主要使用Objective-C语言来研究和实现与外部配件的交互。Objective-C是iOS开发中较为传统但强大的编程语言,它通过对象和消息传递机制,为开发者提供了丰富的交互方式。 1. 导入ExternalAccessory框架 首先,在项目中导入ExternalAccessory框架是使用其API的前提。在Xcode中,可以通过在项目的Build Phases设置中添加ExternalAccessory.framework来实现。 2. 检测附件 要与外部配件交互,第一步是检测设备连接了哪些附件。在Objective-C中,我们通过实现`AAPLAccessoryPickerDelegate`协议中的方法来完成这一功能。当附件可用时,可以通过附件代理对象调用`picker:didPickUpAccessories:`方法。 3. 与附件通信 一旦检测到外部附件,应用程序就需要与之通信。这通常涉及到获取附件的唯一标识符,建立与附件的服务会话,并通过定义好的协议进行数据的发送与接收。 - 访问附件信息:通过`accessory информации`方法可以获取到附件的详细信息,如名称、制造商、型号等。 - 建立通信会话:使用`beginSessionWithService:options:completion:`方法来开始与附件的服务会话,完成回调后即可与配件通信。 - 发送接收数据:数据的发送与接收通常通过流(Stream)来完成,包括输入流和输出流,分别对应附件提供的数据输入和输出服务。 三、编码实践 了解了ExternalAccessory框架的使用方法后,我们将通过一个简单的示例来实践如何在Objective-C中与外部配件进行通信。 1. 创建项目 首先在Xcode中创建一个新的项目,确保已经将ExternalAccessory.framework添加到项目中。 2. 实现附件代理 创建一个新的Objective-C类,实现`AAPLAccessoryPickerDelegate`协议,并在其中处理附件的选择和通信流程。 ```objective-c #import <ExternalAccessory/ExternalAccessory.h> @interface AccessoryManager : NSObject <AAPLAccessoryPickerDelegate> @end @implementation AccessoryManager { AAPLAccessoryPicker *picker; } - (void)showAccessoryPicker { if (picker == nil) { picker = [AAPLAccessoryPicker sharedPicker]; } picker.delegate = self; [picker show]; } #pragma mark - AAPLAccessoryPickerDelegate - (void)picker:(AAPLAccessoryPicker *)picker didPickUpAccessories:(NSArray *)accessories { // 对选择的附件进行处理 AAPLAccessory *selectedAccessory = [accessories firstObject]; [self connectToAccessory:selectedAccessory]; } - (void)connectToAccessory:(AAPLAccessory *)accessory { // 建立会话并进行通信 NSString *serviceString = @"com.example.AccessoryService"; EASession *session = [accessory beginSessionWithService:serviceString options:nil completion:^(NSError *error) { if (!error) { // 会话建立成功,可以进行数据通信 } }]; } @end ``` 3. 数据通信 在建立了会话之后,我们可以通过会话对象的输入输出流来发送和接收数据。 ```objective-c NSData *dataToSend = ...; // 准备要发送的数据 EASession *session = ...; // 已经建立的会话 OutputStream *outputStream = [session outputStream]; [outputStream writeData:dataToSend withCompletionHandler:^(NSError *error) { if (!error) { // 数据发送成功 } }]; InputStream *inputStream = [session inputStream]; [inputStream readDataToLength:... withCompletionHandler:^(NSData *data, NSError *error) { if (!error) { // 数据接收成功,data即为接收到的数据 } }]; ``` 四、总结 ExternalAccessory.framework为iOS应用提供了与外部配件交互的API。通过本篇文章的学习,开发者可以了解到如何在Objective-C项目中引入该框架,检测和选择附件,以及与附件进行数据通信的基本流程。在实际应用中,开发者还需要针对具体的配件进行协议和服务的定义,以及异常处理和资源管理等高级功能的实现。 本篇知识总结旨在为开发者提供一个系统化的介绍和实践指导,帮助开发者更好地理解和应用ExternalAccessory.framework,从而开发出能够与外部配件进行有效交互的iOS应用。

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer com.cz.JobWeb.controller.persController.ShowOneComInfo(persController.java:39) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:893) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:807) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1061) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) javax.servlet.http.HttpServlet.service(HttpServlet.java:515) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:583) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)

2023-06-02 上传

top.mcshy.CloudSea.service.impl.StrategyServiceImpl.updateStrategyImg(StrategyServiceImpl.java:48) top.mcshy.CloudSea.controller.StrategyController.updateStrategyImg(StrategyController.java:78) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) javax.servlet.http.HttpServlet.service(HttpServlet.java:681) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

2023-05-25 上传
2023-07-09 上传

main SpringApplication.java:771 - Application startup failed org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is org.springframework.cloud.stream.binder.BinderException: Exception thrown while starting consumer: at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348) at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) at com.migu.rstone.UserCenterApplication.main(UserCenterApplication.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: org.springframework.cloud.stream.binder.BinderException: Exception thrown while starting consumer: at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:258) at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:57) at org.springframework.cloud.stream.binder.AbstractBinder.bindConsumer(AbstractBinder.java:145) at org.springframework.cloud.stream.binding.BindingService.bindConsumer(BindingService.java:97) at org.springframework.cloud.stream.binding.BindableProxyFactory.bindInputs(BindableProxyFactory.java:221) at org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:55) at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) ... 22 more Caused by: java.lang.IllegalArgumentException: A list of partitions must be provided at org.springframework.util.Assert.isTrue(Assert.java:92) at org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder.createConsumerEndpoint(KafkaMessageChannelBinder.java:241) at org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder.createConsumerEndpoint(KafkaMessageChannelBinder.java:88) at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:217) ... 28 more 报错解决办法

2023-07-15 上传

java.lang.NullPointerException: null at com.datech.web.controller.system.TbappController.remove(TbappController.java:667) at com.datech.web.controller.system.TbappController$$FastClassBySpringCGLIB$$ea1c3ba.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor$1.proceed(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:82) at org.apache.shiro.authz.aop.AuthorizingMethodInterceptor.invoke(AuthorizingMethodInterceptor.java:39) at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor.invoke(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:115) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) at com.datech.web.controller.system.TbappController$$EnhancerBySpringCGLIB$$b3b02033.remove(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2023-07-14 上传
2023-06-03 上传