Cocoa 的蓝牙示例代码(Objective-C)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1605081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:22:54  来源:igfitidea点击:

Bluetooth Example Code for Cocoa (Objective-C)

objective-ccocoaxcodemacosbluetooth

提问by Stuart Berg

I'm looking for example code for setting up a connection to a bluetooth device using the Bluetooth API in Cocoa. Apple used to include this type of example code in the XCode tools package under the /Developer/Examples/Bluetooth folder, but upon downloading the latest version of XCode (3.2.1), these bluetooth examples have been removed from that directory.

我正在寻找使用 Cocoa 中的蓝牙 API 设置与蓝牙设备的连接的示例代码。Apple 曾经将此类示例代码包含在 /Developer/Examples/Bluetooth 文件夹下的 XCode 工具包中,但在下载最新版本的 XCode(3.2.1)后,这些蓝牙示例已从该目录中删除。

There is now a readme file located at /Developer/Examples/ReadMe.rtf that explains that all example code is on the ADC website. However, it seems that the ADC website does NOT include bluetooth sample code.

现在有一个位于 /Developer/Examples/ReadMe.rtf 的自述文件,解释了所有示例代码都在 ADC 网站上。但是,ADC 网站似乎不包含蓝牙示例代码。

I've tried googling, but I can't seem to find any good examples for how to get bluetooth going on Mac OS X with Cocoa. Can anybody help me out? I wish I had copied those examples to a backup location before updating to XCode 3.2.1! Curses, Apple! Why have you taken them from me?

我试过谷歌搜索,但我似乎找不到任何很好的例子来说明如何使用 Cocoa 在 Mac OS X 上启用蓝牙。有人可以帮我吗?我希望在更新到 XCode 3.2.1 之前将这些示例复制到备份位置!诅咒,苹果!你为什么要从我这里拿走它们?

采纳答案by outis

You can do what I've done: download an old copy of XCode and use Pacifistto extract what you need.

你可以做我所做的:下载 XCode 的旧副本并使用Pacifist来提取你需要的东西。

回答by Matthieu Cormier

I recently went through my backups to look at this code and have posted it in case anyone wants to look at it.

我最近查看了我的备份以查看此代码并已将其发布,以防有​​人想查看它。

http://cs.dal.ca/~mcormier/Bluetooth.zip

http://cs.dal.ca/~mcormier/Bluetooth.zip

Please note that if you plan on working with Bluetooth for iOS devices then you want to use the Game Kit Peer-to-Peer Connectivity API and not this code.

请注意,如果您计划为 iOS 设备使用蓝牙,那么您需要使用 Game Kit Peer-to-Peer Connectivity API 而不是此代码。

回答by geowar

Let Apple know you need these by filing a bug report (enhancement request) at https://bugreport.apple.com.

通过在https://bugreport.apple.com提交错误报告(增强请求)让 Apple 知道您需要这些。

回答by C0D3

This (http://www.devx.com/wireless/Article/43502/0/page/1) shows the GameKit bluetooth to connect with ipads, iphones and ipods I believe. I got the code to work and run but couldn't connect with another device whoose bluetooth was on but only my phone was running the application built with this code. So maybe both need to run it? Anyways, hope it helps a bit, I'm also researching a better tutorial where I can actually connect to bluetooth devices and not just ipad, iphone or ipods. If I write something that works, i'll make sure to blog about it here: blog.

这(http://www.devx.com/wireless/Article/43502/0/page/1)显示了 GameKit 蓝牙连接我相信的 ipad、iphone 和 ipod。我使代码可以工作并运行,但无法与另一台打开蓝牙的设备连接,但只有我的手机正在运行使用此代码构建的应用程序。那么也许两者都需要运行它?无论如何,希望它有所帮助,我也在研究一个更好的教程,在那里我可以实际连接到蓝牙设备,而不仅仅是 ipad、iphone 或 ipods。如果我写了一些有用的东西,我一定会在这里写博客blog