BluetoothManager not working on iOS 7

限于喜欢 提交于 2019-12-06 06:47:07

问题


I'm trying to use BluetoothManager in an app on iOS 7 but it doesn't seem to be working.

Calling setEnabled: and setPowered: on BluetoothManager doesn't have any effect, and I'm registering for notifications (BluetoothAvailabilityChangedNotification) but these are never sent.

I've imported the framework and I'm using example code as given by these questions, but these are all pre-iOS 7, which may be the problem;

iOS BluetoothManager Framwork
iOS: Can't get BluetoothManager to work
Programmatically turn on bluetooth in the iphone sdk?


回答1:


Turns out that this framework hasn't been protected in iOS 7 and is still available for use.

I believe the problem was with the location of the BluetoothManager.h and BluetoothDevice.h header files. They need to be located in the following directory: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework/Headers

And the "Framework Search Paths" build setting of your project needs to include $(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks for it to use these files.

I'm not sure why this worked - having the header files in the Xcode project still returned a valid(?) object for [BluetoothManager sharedInstance] but simply didn't give any other functionality. At least now it works, yay!

Oh and I should mention how I discovered this! michaeldorner's "BeeTee" github project is pretty much a basic BluetoothManager sample project designed for iOS 7. The readme file describes the header file placement, other than that it was just the build setting in his project to enable these headers to be used.




回答2:


I don't have enough rep to comment but I'd like to add a little more information about this issue. I've found that the above solution and even the original solutions that were linked to in the OP both work when XCode is building for armv7, armv7S, and arm64 on my iPhone 5s.

However if one changes the build settings to only build for the standard architectures (armv7, armv7s) the product will build but the calls to setEnabled and setPowered will have no effect like the OP mentions.



来源:https://stackoverflow.com/questions/19858710/bluetoothmanager-not-working-on-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!