Getting 3 error messages when trying to compile code in Xcode 7 for IOS 9

1) Property iSconnected not found on object of type CBPeripheral


and


2) Property UUID not found on object of type CBPeripheral


and


3) No visible @interface for CBCentral Manager retrieveConnected Peripheral


Code runs fine in XCode 6.3.2


This is all regarding BLE 4.0

Replies

It would appear that UUID and isConnected are depreciated...

https://developer.apple.com/library/prerelease/ios/documentation/CoreBluetooth/Reference/CBPeripheral_Class/index.html#//apple_ref/occ/cl/CBPeripheral


You need to use CBCentralManager retrieveConnectedPeripheralsWithServices: now, retrieveConnectedPeripherals appears to be depreciated

https://developer.apple.com/library/prerelease/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html#//apple_ref/occ/cl/CBCentralManager

For iOS 9, I know that isConnected, UUID, and retrieveConnectedPeripherals are deprecated.


My target platform is iOS 6.0, so I still need to use these for 6.0. If you include any of the deprecated items it will cause a build error like:


No visible @interface for 'CBCentralManager' declares the selector 'retrieveConnectedPeripherals'


How do I build for for a target of iOS 6.0 if these items have been removed from the SDK?


Thanks

You can generally check ot see if an object responds to a message and if it does, use it, otherwise use some other code as an alternative.


That should deal with the error message.

This is a compile time error. I understand the respondsTo checking....


+(BOOL)isPeripheralConnected:(CBPeripheral *)cbp{

if ([cbp respondsToSelector:@selector(isConnected)]){

return cbp.isConnected); <<<---------------- This will give you a compile time error because isConnected is not defined in the iOS 9 SDK

}

}


My build target is iOS 6.x

I haven't faced that issue.

Apple had generally suggested the responds to method.


A possible work around is to define a method with the same signature.

You don't have to actually use it, but it gives the compiler a known method.


Cast the cpb as an (id).

It might also be worthwhile casting the results as well.


This stops the compile time messages.


The basic error reflects ARC not knowing how to handle the results, so it may get problematic using this approach for objects.


I'm at work and can't test this at the moment, other than confirming no compile time errors.

Disable the ARC

  1. Select
    Project
  2. Select
    Targets
  3. From the right panel, select
    Build Settings
  4. Search for "Automatic Reference Counting";
  5. select
    NO
    in all three sections.