centralManagerDidUpdateState委托未被调用

时间:2015-01-07 04:49:56

标签: c++ ios objective-c bluetooth communication

我正在使用CoreBluetooth框架在MAC上进行蓝牙通信。

使用Pure Objective C,代码运行良好。

我想从cpp调用Objective c代码,我正在使用包装器函数来执行此操作并初步化了centralManager。但是没有调用centralManagerDidUpdateState委托(即中央管理器没有启动)。

在处理来自cpp类的目标c委托时,是否需要注意一些事项?

我是Objective c编码的新手。对此的任何输入都会有所帮助。

代码:

CInterface.h->

  void wrapperFunction();

main.cpp - >

#include <CInterface.h>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    wrapperFunction();
    return a.exec();
}

MyDelegateObject.h - &gt;

#include <CInterface.h>
#include <IOBluetooth/IOBluetooth.h>

@interface MyDelegateObject : NSObject <CBCentralManagerDelegate> {

}

- (void) centralManagerDidUpdateState:(CBCentralManager *)central;
@end

MyDelegateObject.mm-&GT;

@implementation MyDelegateObject

void wrapperFunction(){
    qDebug()<<"Inside Wrapper function";
    MyDelegateObject *myDelegate = [MyDelegateObject alloc];
    CBCentralManager *myCentralManager = [[CBCentralManager alloc] initWithDelegate:myDelegate queue:nil]; 
}

- (void) centralManagerDidUpdateState:(CBCentralManager *)central
{
    qDebug()<<"inside delegate";
}

它的enctring进入wrapperFunction,我能够获得&#34; Inside Wrapper功能&#34;打印。 但是在initWithDelegate之后,应该调用centralManagerDidUpdateState。这不会发生。

我错过了什么吗?

谢谢, SK

0 个答案:

没有答案
相关问题