Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios6 连接后立即断开iOS 6外围设备_Ios6_Connection_Core Bluetooth_Cbperipheral - Fatal编程技术网

Ios6 连接后立即断开iOS 6外围设备

Ios6 连接后立即断开iOS 6外围设备,ios6,connection,core-bluetooth,cbperipheral,Ios6,Connection,Core Bluetooth,Cbperipheral,好的,我正在使用核心蓝牙将我的I-Pad连接到另一个BLE传感器。 我很容易扫描并检测它,但当我想建立连接时,“did connect peripheral”方法只在30秒内调用,就好像我调用了断开连接一样。。。 即使我在所需的后台模式下选择或取消选择“应用程序使用CoreBooth进行通信”,该结果仍然保持不变 - (id) init { self = [super init]; if (self) { pendingInit = YES;

好的,我正在使用核心蓝牙将我的I-Pad连接到另一个BLE传感器。 我很容易扫描并检测它,但当我想建立连接时,“did connect peripheral”方法只在30秒内调用,就好像我调用了断开连接一样。。。 即使我在所需的后台模式下选择或取消选择“应用程序使用CoreBooth进行通信”,该结果仍然保持不变

- (id) init
{
    self = [super init];
    if (self) 
    {
         pendingInit = YES;
         centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];

         foundPeripherals = [[NSMutableArray alloc] init];
         connectedServices = [[NSMutableArray alloc] init];
    }
    return self;
}



- (void) centralManagerDidUpdateState:(CBCentralManager *)central
{
     static CBCentralManagerState previousState = -1;
     switch ([centralManager state]) 
     {
         case CBCentralManagerStateUnsupported:
         {
             NSLog(@"NSCentralManager State Unsupported...");
             break;
         }
         case CBCentralManagerStatePoweredOff:
         {
             NSLog(@"NSCentralManager State Powered OFF");
             [self clearDevices];
             [discoverPeripheralDelegate discoveryDidRefresh];

             if (previousState != -1) 
             {
                 [discoverPeripheralDelegate discoveryStatePoweredOff];
             }
             break;
         }

         case CBCentralManagerStateUnauthorized:
         {
             NSLog(@"NSCentralManager State Unauthorized: the application is not allowed");
             break;
         }

         case CBCentralManagerStateUnknown:
         {
             NSLog(@"NSCentralManager state unknown... Bad News...");
             break;
         }

         case CBCentralManagerStatePoweredOn:
         {
             NSLog(@"NSCentralManager State Powered ON!");
             pendingInit = NO;
             [self loadSavedDevices];

             [centralManager retrieveConnectedPeripherals];
             [discoverPeripheralDelegate discoveryDidRefresh];
             break;
         }

         case CBCentralManagerStateResetting:
         {
             NSLog(@"CBCentralManager State Resetting");
             [self clearDevices];
             [discoverPeripheralDelegate discoveryDidRefresh];
             [peripheralDelegate alarmServiceDidReset];

             pendingInit = YES;
             break;
         }
     }
     previousState = [centralManager state];
}


- (void) loadSavedDevices
{
     storedDevices = [[NSArray alloc] initWithObjects:kPressureServiceUUIDString, nil];

     for (id deviceUUIDString in storedDevices) {

          if (![deviceUUIDString isKindOfClass:[NSString class]])
              continue;

          CFUUIDRef uuid = CFUUIDCreateFromString(NULL, (CFStringRef)deviceUUIDString);
          if (!uuid)
              continue;

          storedUUIDs = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"StoredUUIDS"]];
          for (int i = 0; i < storedUUIDs.count; i++) {
              NSArray * tempStoredUUIDs = storedUUIDs[i];
              storedUUIDs[i] = [tempStoredUUIDs mutableCopy];
          }

          [centralManager scanForPeripheralsWithServices:nil options:nil];
          storedUUIDs = [[NSMutableArray alloc] init];
          [[NSUserDefaults standardUserDefaults] setObject:storedUUIDs forKey:@"StoredUUIDS"];
      }
} 




- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSString * finaluuids = [NSString stringWithFormat:@"%@",peripheral.UUID];
    if (storedUUIDs.count == 0)
    {
        storedUUIDs = [[NSMutableArray alloc] initWithObjects:finaluuids, nil];
        [centralManager stopScan];
        [centralManager connectPeripheral:peripheral options:nil];
    }
}




- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    NSLog(@"connected");
}
如何避免连接后立即断开外围设备?
它让我发疯

您必须在DidDiscoveryPeripal上执行[peripheral retain],或将其放入retain属性。
它在通过BLE框架连接后立即释放。

我有一个错误:尝试连接到外围传感器已断开连接:指定的设备已与我们断开连接。您是否使用
CBPeripheral
对象,连接时:
yourpheral=peripal
中的
didConnect
委托并设置其委托:
yourpheral setDelegate:self
(self或另一个类)?您连接的实际BLE设备是什么?
2013-05-14 09:21:14.925 PRESSURE[262:907] connected
2013-05-14 09:21:14.927 PRESSURE[262:907] Service (Sensor) connected
2013-05-14 09:21:44.994 PRESSURE[262:907] Service (Sensor) disconnected