【发布时间】:2014-04-07 11:24:58
【问题描述】:
我正在开发我的第一个蓝牙应用程序。现在我有一个 AppUIview,它实现了一个按钮,该按钮调用 AppCentralManager 中的一个函数,蓝牙功能将在其中实现:
- (IBAction) Scan{
NSLog(@"scan function");
[[AppBluetoothCenter alloc]initialize];
}
在 AppBluetoothCenter.h 我已经声明了这些函数:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <CoreBluetooth/CBService.h>
#import "AppDelegate.h"
@interface AppBluetoothCenter : NSObject <UIApplicationDelegate,CBCentralManagerDelegate, CBPeripheralDelegate>
@property CBCentralManager* CentralManager;
- (void) initialize;
@end
在 AppBluetoothCenter.m 中我实现了以下功能:
#import "AppBluetoothCenter.h"
@implementation AppBluetoothCenter
-(void)initialize{
NSLog(@"initialize");
_CentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOff){
NSLog(@"BLE OFF");
}
else if (central.state == CBCentralManagerStatePoweredOn){
NSLog(@"BLE ON");
}
else if (central.state == CBCentralManagerStateUnknown){
NSLog(@"NOT RECOGNIZED");
}
else if(central.state == CBCentralManagerStateUnsupported){
NSLog(@"BLE NOT SUPPORTED");
}
}
@end
在我收到的日志控制台中运行应用程序:
AppBluetooth[1273:60b] 扫描功能
AppBluetooth[1273:60b] 初始化
为什么没有调用centralManagerDidUpdateState?
【问题讨论】:
-
您在哪个设备上运行您的应用程序?
-
我在 Iphone5 和 Iphone4 上运行过,都使用 iOS7
-
只有 iPhone4S+ 支持 BLE。检查developer.apple.com/library/ios/samplecode/TemperatureSensor/… 是否适合您。
-
我知道,该应用程序也在 iphone5 上运行。但无论如何,如果我在 iPhone4 中运行应用程序,central.state 的结果应该是 CBCentralManagerStateUnsupported
标签: ios objective-c bluetooth-lowenergy core-bluetooth cbcentralmanager