Mac应用程序和iOS应用的蓝牙/无线网络 [英] Bluetooth/WiFi between Mac app and iOS app

查看:234
本文介绍了Mac应用程序和iOS应用的蓝牙/无线网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能与iOS应用程序连接并发送消息蓝牙Mac应用程序?

How can I make a Bluetooth Mac app that connects with an iOS app and sends messages ?

或者说通过本地WiFi网络与Mac应用程序连接iOS应用?

Or an iOS app that connects with a Mac app via a local WiFi network ?

推荐答案

请注意:这个答案现在已经过时,与自iOS6的和OSX 10.7引进CoreBluetooth(蓝牙LE V4)的任何iOS设备是开放给任何形式的沟通与其他任何BLE兼容设备,Mac或PC或外部硬件。
下面的答案仍然是有效的,如果你不能支持BLE,由于旧的硬件或特定要求(例如,所需的带宽)

NOTE: this answer is now outdated as with the introduction of CoreBluetooth (Bluetooth LE v4) since iOS6 and OSX 10.7 any iOS device is open to any kind of communication with any other BLE compatible device, either a Mac or PC or external hardware. The answer below is still valid if you cannot support BLE, due to old hw or specific requirements (e.g. required bandwidth)

据我所知,这几乎是不可能的。 iOS设备之间的蓝牙连接以及与框架的GameKit支持,但是有与其他操作系统的连接的支持,包括OSX。我所见过的Mac和iPhone之间的连接只能是与热点功能(工作时)。
例如,考虑主旨远程应用程序。该应用程序允许你使用你的iPhone作为遥控器来控制一个主题presentation。它允许这种控制,当两个设备基调配对的WiFi,但使用蓝牙连接,这是不允许的,同时用蓝牙可以控制两个iOS设备之间的主旨presentation。你可以找到苹果这一说法技术说明2152:

As far as I know, this is almost impossible. Bluetooth connection between iOS devices is well supported with the GameKit framework but there is no support for connection with other OSes, OSX included. The only connection between Mac and iPHone I have ever seen is with the hotspot feature (when it works). Consider for example the Keynote Remote app. This app allows you to control a Keynote presentation using your iPhone as a remote. It allows this control when the two devices are Keynote-paired on the WiFi, but this connection is not allowed using Bluetooth, while with Bluetooth you can control a Keynote presentation between two iOS devices. And you can find this statement in Apple tech note 2152:

An important consequence of the first point is that Bluetooth peer-to-peer networking can only be used to communicate between iOS devices; you can't use it, for example, to communicate between an iOS device and a computer running Mac OS X.

至于无线的问题(我忘了在我的第一个问题回复吧)基本上你样的问题要解决:发现性和数据传输。为了确定两个设备都在同一网络中,可以使用Bonjour的协议。从本质上讲一体机发布自己作为服务提供商的特定服务(你可以创建自己的服务:例如_mytype._myprotocol)和可能的客户端将搜索服务器。 。除了卓悦需要照顾其他像地址和DNS没有两个应用程序知道本地网络,他们都在细节这是在这里的苹果文档解释:<一href=\"http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NetServices/Articles/about.html\" rel=\"nofollow\">http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NetServices/Articles/about.html
需要注意的是Bonjour是在功能,如AirPlay的(苹果电视),AirPrint的大概也空投了基础,但它是由很多的设备,例如支持一些NAS。在苹果开发者网站,你会发现一个很好的例子,被称为BonjourWeb的样品codeS部分,显示服务发现是如何工作的。您可以轻松地尝试在你的iPhone模拟器或设备,如果你有一些支持Bonjour的设备,你会看到它在列表中。
当然,第二个问题则是在两个设备之间实现数据通信,是由你来定义一个定制的客户端/服务器,或者使用标准的Web服务器为基础的方法。这取决于应用和数据流。第一种方法是更好,因为它是高度定制的,你必须研究NetworkStreams概念和苹果库检查出SimpleNetworkStreams code(这是一台Mac和iPhone之间的简单通信的应用程序;不总是工作,但它是一个很好的起点)

As far as the WiFi question (I forgot to reply to it in my first question) essentially you to kind of problems to solve: discoverability and data transfer. In order to determine if two devices are in the same network, you can use the Bonjour protocol. Essentially one of the machines publish itself as service-provider for a specific service (you can create your own service: e.g. "_mytype._myprotocol") and the would-be client will search for a server. Besides Bonjour takes care of other things like addressing and DNS without the two apps to know the details of the local network they are in. This is explained in Apple docs here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NetServices/Articles/about.html Note that Bonjour is at the base of features like AirPlay (Apple TV), AirPrint and probably also AirDrop but it is supported by a lot of devices, e.g. some NAS. In the SampleCodes section of the Apple developers site you will find a great example, called "BonjourWeb" that shows how service discovery works. You can easily try it in your iPhone simulator or device and if you have some Bonjour-enabled device you will see it in the list. The second problem of course is then real data communication between the two devices, is up to you to define a custom client/server or use a standard web-server based approach. This depends on the application and the data flow. The first approach is better as it is highly customized, you must study the NetworkStreams concepts and check out the SimpleNetworkStreams code in the apple library (this is a simple communication app between a Mac and an iPhone; not always working but it is a good starting point)

这篇关于Mac应用程序和iOS应用的蓝牙/无线网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆