Ios7 蓝牙中央管理器未连接到新服务

Ios7 蓝牙中央管理器未连接到新服务,ios7,core-bluetooth,cbcentralmanager,cbperipheral,Ios7,Core Bluetooth,Cbcentralmanager,Cbperipheral,我正在尝试创建一个应用程序,其中两个不同的设备可以使用相同的uicontrol视图相互通信,使用iBeacon来回发送通知,并使用bluetoothle来回发送数据 我首先发送了一个电子地图,询问该地区的人们是否想玩游戏 如果收到通知的人点击OK按钮,他们会发布一个蓝牙特性,该特性的值是原始用户正在监听的唯一用户id和服务,然后会发出一个iBeacon通知,提醒原始用户他们想要玩 完成此操作后,应用程序停止外围广告,并开始centralManager根据其自己的用户ID和部分UUID扫描不同的服

我正在尝试创建一个应用程序,其中两个不同的设备可以使用相同的uicontrol视图相互通信,使用iBeacon来回发送通知,并使用bluetoothle来回发送数据

我首先发送了一个电子地图,询问该地区的人们是否想玩游戏

如果收到通知的人点击OK按钮,他们会发布一个蓝牙特性,该特性的值是原始用户正在监听的唯一用户id和服务,然后会发出一个iBeacon通知,提醒原始用户他们想要玩

完成此操作后,应用程序停止外围广告,并开始centralManager根据其自己的用户ID和部分UUID扫描不同的服务UUID

我使用位置管理器获取邀请通知。然后,当点击OK按钮时,我使用

    -(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

        if (AlertView) {
         NSLog(@"idenify:%@",identifierString);
            if ([identifierString isEqualToString:@"com.checkers.bluetooth"]) {
                    if (buttonIndex == 0) {
                        [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ 
//here I clear the CentralManager so a new service can be looked for
centralManager = nil;
//here the peripheralManager sends the unique code
[self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:sendUUID]] }]; recieve.frame = CGRectMake(147,55,20,20);  } completion:^ (BOOL completed) {
//here the peripheralManager sends the proximity notification
 NSUUID * uid = [[NSUUID alloc] initWithUUIDString:@"55DCE9F4-7942-4B9D-B914-50426D6CC976"];
                        self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uid identifier:@"com.checkersok.bluetooth"];
                        [self configureTransmitter];
                           [self.peripheralManager startAdvertising:self.peripheralData];inviteCheckers.hidden = YES; [self.recieve setBackgroundImage:[UIImage imageNamed:@"accept.png"] forState:UIControlStateNormal];[UIView animateWithDuration:1 delay:2 options:UIViewAnimationOptionCurveEaseIn animations:^{ movementImage.frame = CGRectMake(300,292,17,17);
                        } completion:^ (BOOL completed) {
//here the peripheral manager is stopped
 [self.peripheralManager stopAdvertising];
                            NSString *startString2 = userId.text;
                            NSString *endString2 = [startString2 stringByAppendingString:@"-2C29-40E0-8E1E-1D7A9E5D0964"];
                            recieverUUID =endString2;
                            self.userUUIDString = @"YES";
                            NSLog(@"userUUIDString2;%@",userUUIDString);
                            NSLog(@"recieverUUID7;%@",recieverUUID);

//here the centralManager is allocated again and starts scanning for the new service UUID
 centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
                            [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:recieverUUID]] options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];}         ];}         ];


                        NSLog(@"userUUIDString:%@",userUUIDString);

                        [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
                        [[UIApplication sharedApplication] cancelAllLocalNotifications];
                }
当发送方收到有人愿意播放的通知时,我将外围设备管理器设置为零,以便可以将其设置为其他内容

当原始个人发送者点击OK按钮时,我会重新锁定外围设备管理器,并根据第二个人用户ID和UUID的同一端开始广播服务UUID。这是sendUUID

else if ([identifierString isEqualToString:@"com.checkersok.bluetooth"]) {
            if (buttonIndex == 0) {

                [timer4 invalidate];
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
               [self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:sendUUID]] }];
                 movementImage.frame = CGRectMake(283,292,17,17);  } completion:^ (BOOL completed) {
                    }         ];
                [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
                [[UIApplication sharedApplication] cancelAllLocalNotifications];
                self.userUUIDString = userField.text;

            }
这就是问题所在。 我知道正在调用外围设备管理器并发送数据,并且CentralManager正在通过日志进行连接

这是发件人日志

2014-07-23 16:34:53.215 BTLE Games[344:60b] self.peripheralManager powered on.
2014-07-23 16:34:53.218 BTLE Games[344:60b] transfer char1:(
    "<CBMutableCharacteristic: 0x17db26f0 UUID = C63CBCC0-6DE3-48D5-BB59-2BEFB9F3AE01, Value = (null), Properties = 0x10, Permissions = 0x1, Descriptors = (null), SubscribedCentrals = (\n)>"
)
2014-07-23 16:34:53.220 BTLE Games[344:60b] serviceUUID;CDEF5678-2C29-40E0-8E1E-1D7A9E5D0964
2014-07-23 16:34:54.030 BTLE Games[344:60b] Central subscribed to characteristic
2014-07-23 16:34:54.032 BTLE Games[344:60b] datatosend2:<41424344 31323334>
2014-07-23 16:34:54.033 BTLE Games[344:60b] stringOne:ABCD1234
这是接收日志

2014-07-23 17:22:39.723 BTLE Games[358:60b] CoreBluetooth[WARNING] <CBCentralManager: 0x170247ec0> is disabling duplicate filtering, but is using the default queue (main thread) for delegate events
2014-07-23 17:22:39.724 BTLE Games[358:60b] CoreBluetooth[API MISUSE] <CBCentralManager: 0x170247ec0> can only accept commands while in the powered on state
2014-07-23 17:22:39.743 BTLE Games[358:60b] Discovered iPhone at -50
2014-07-23 17:22:39.744 BTLE Games[358:60b] Connecting to peripheral <CBPeripheral: 0x1782a0480 identifier = DFDBFE05-B652-D5AD-ABA7-10162669E837, Name = "iPhone", state = disconnected>
2014-07-23 17:22:39.745 BTLE Games[358:60b] Discovered iPhone at -50
2014-07-23 17:22:39.747 BTLE Games[358:60b] Peripheral Connected
2014-07-23 17:22:39.747 BTLE Games[358:60b] Scanning stopped
2014-07-23 17:22:39.748 BTLE Games[358:60b] recieverUUIDP;CDEF5678-2C29-40E0-8E1E-1D7A9E5D0964
2014-07-23 17:22:39.965 BTLE Games[358:60b] discovered characteristic13 C63CBCC0-6DE3-48D5-BB59-2BEFB9F3AE01
2014-07-23 17:22:39.966 BTLE Games[358:60b] Found Notify Characteristic31 <CBCharacteristic: 0x17808f730 UUID = C63CBCC0-6DE3-48D5-BB59-2BEFB9F3AE01, Value = (null), Properties = 0x10, Notifying = NO, Broadcasting = NO>
2014-07-23 17:22:39.967 BTLE Games[358:60b] value1:(null)
2014-07-23 17:22:40.009 BTLE Games[358:60b] CoreBluetooth[WARNING] <CBCentralManager: 0x170247ec0> is disabling duplicate filtering, but is using the default queue (main thread) for delegate events
2014-07-23 17:22:40.010 BTLE Games[358:60b] 
正如您所看到的,外围设备管理器正在进行广告宣传,而中央管理器正在进行扫描。 中央处理器找到外围设备并连接,但停止。通常,外围设备会继续播发数据,而中央设备在获取数据之前,必须连接和断开几次连接。这就是我不知道如何开始工作的原因,因为我使用相同的代码发送和接收这些数据,并且我使用从第二个人发送到第一个人的数据

我试过几种不同的方法来让它工作,但都做不到。
有人能告诉我如何让它工作吗?

为什么不仅仅是多个EER连接框架?不知道你的意思。ios中有一个称为多个EER连接框架的框架,它可以完成你在这里尝试做的所有事情,并且它可以在wifi和Bluetooth上运行。你应该实施委托方法删除警告。你应该简单地回答你的问题,只包含重现问题的相关代码只能在处于开机状态时接受命令表示您在尝试使用中央管理器之前没有等待中央管理器报告它处于开机状态-您是否正确实现了CentralManagerDipDateState:?