iOS中多个CMMotionManager冲突如何解决?
我想为一些应用程序开发人员创建一个自定义的 UIView 类(静态库)。我在代码中创建了 CMMotionManager 实例。我发现,如果应用程序开发人员还在其代码中创建 CMMotionManager 实例,我们的 CMMotionManager 实例之一将无法处理陀螺仪/加速度计值。我意识到 UIWebview 可以在应用程序获取这些值时获取这些值(例如 javascript 代码:window.ondevicemotion = function(e) {...}),我认为可能有一种方法可以避免这种冲突。关于如何避免这种冲突有什么想法吗?
I want to create a customized UIView class (a static lib) for some app developers. I have created CMMotionManager instance in my code. I've found that if an app developer also creates the CMMotionManager instance in his code, one of our CMMotionManager instance will fail to handle the gyro/accelerometer values. I realize that the UIWebview can get these values (e.g. javascript code: window.ondevicemotion = function(e) {...}) while the app is getting them, I think there might be a way to avoid this conflict. Any ideas about how to avoid this conflict?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 CLLocation 管理器一样,您应该只为每个应用程序实现一个 CMMotionManager 实例,我建议创建一个单例类并从那里访问您的 CMMotionManager,请参阅这篇文章
CMMotionManager 是全局资源?这意味着什么?
As with the CLLocation manager you should only implement one instance of CMMotionManager per app, I would recommend creating a singleton class and accessing your CMMotionManager from there, see this post
CMMotionManager is a global resource? What does this means?