• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework


  • Subject: Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework
  • From: Sal Conigliaro <email@hidden>
  • Date: Sat, 19 Oct 2013 12:11:59 -0400

You have the reference correctly. 

In looking at your code, I think what's happening is
you are finding the first peripheral and starting to connect

While you're still trying to connect to the first peripheral,
you get the callback for the second peripheral (which deallocs
the reference to the first peripheral. 

Instead of having a single pointer for the peripherals,
use a mutable array and put each discovered peripheral into
that array (later on you'll have to search for/look at each one
to see if that's the one you want to discover services
on (or whatever you're doing after they're connected))

Sal
--
Sal Conigliaro,
e design
www.erinedesign.com
@sconig

On Oct 19, 2013, at 11:20 AM, Richard Lipes <email@hidden> wrote:

I am using the following construct in my code:

@property (nonatomic, strong) CBPeripheral *discoveredPeripheral;


. . .


(void)centralManager:(CBCentralManager *)centralManager didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {


. . .


    if (self.discoveredPeripheral != peripheral) {

        self.discoveredPeripheral = peripheral;

        NSLog(@"didDiscoverPeripheral Connecting to peripheral %@", peripheral.name);

        // Connects to the discovered peripheral

        [centralManager connectPeripheral:peripheral options:nil];

. . .

    }

}


Should the strong reference be done differently or made in a different delegate method?


From: Sal Conigliaro <email@hidden>

Date: Friday, October 18, 2013 3:45 PM
To: Richard Lipes <email@hidden>
Cc: <email@hidden>
Subject: Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework

The pointer you're using to hold the peripheral is a weak reference and is being deallocated:

2013-10-18 13:58:37.079 BlueMarco[1137:60b] CoreBluetooth[WARNING] <CBPeripheral: 0x14e799d0 identifier = 33C98AC7-E25E-0803-82D2-326FC8C0FDB1, Name = "ICServer_2", state = connecting> is being dealloc'ed while connecting

Change it to a strong reference instead.

Sal
--
Sal Conigliaro,
e design
www.erinedesign.com
@sconig

On Oct 18, 2013, at 6:05 PM, Richard Lipes <email@hidden> wrote:

When I scan for 2 peripherals each having a single service and characteristic (with cServiceArray being an NSArray of both service CBUUIDs) with the method:

[self.centralManager scanForPeripheralsWithServices:cServiceArray options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @NO }];

I receive the following console response::

2013-10-18 13:58:37.069 BlueMarco[1137:60b] didDiscoverPeripheral peripheral description <CBPeripheral: 0x14e799d0 identifier = 33C98AC7-E25E-0803-82D2-326FC8C0FDB1, Name = "ICServer_2", state = disconnected>
.  .  .
2013-10-18 13:58:37.072 BlueMarco[1137:60b] didDiscoverPeripheral Connecting to peripheral ICServer_2
.  .  .
2013-10-18 13:58:37.076 BlueMarco[1137:60b] didDiscoverPeripheral peripheral description <CBPeripheral: 0x14e75b60 identifier = E634E343-0DCF-3A4F-1F88-D4C87EA731EA, Name = "ICServer_1", state = disconnected>
.  .  .
2013-10-18 13:58:37.079 BlueMarco[1137:60b] CoreBluetooth[WARNING] <CBPeripheral: 0x14e799d0 identifier = 33C98AC7-E25E-0803-82D2-326FC8C0FDB1, Name = "ICServer_2", state = connecting> is being dealloc'ed while connecting
2013-10-18 13:58:37.080 BlueMarco[1137:60b] didDiscoverPeripheral Connecting to peripheral ICServer_1
2013-10-18 13:58:37.093 BlueMarco[1137:60b] didConnectPeripheral peripheral <CBPeripheral: 0x14e75b60 identifier = E634E343-0DCF-3A4F-1F88-D4C87EA731EA, Name = "ICServer_1", state = connected>

This shows the connection to one peripheral broken as I make a connection to the second server. Is this the expected behavior? If so, why does the method scanForPeripheralsWithServices allow an NSArray of service CBUUIDs as an argument? If not, can anyone show me how to scan for and handle the reception of multiple services?


Richard Lipes

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework (From: Richard Lipes <email@hidden>)

  • Prev by Date: Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework
  • Next by Date: Real time data transmit by BLE (iOS7)
  • Previous by thread: Re: Scanning for and handling reception of multiple services in Core Bluetooth Framework
  • Next by thread: Real time data transmit by BLE (iOS7)
  • Index(es):
    • Date
    • Thread