RxBluetoothKit icon indicating copy to clipboard operation
RxBluetoothKit copied to clipboard

Support iOS 15 SDK

Open bspinner opened this issue 4 years ago • 15 comments

Is your feature request related to a problem? Please describe. Apps using RxBluetoothKit with iOS 15 SDK cannot be built.

Describe the solution you'd like Fix issues related to CoreBluetooth api changes (compiler complains about optionals that need to be unwrapped).

Describe alternatives you've considered None.

Additional context None.

bspinner avatar Jun 16 '21 12:06 bspinner

They seem to have abandoned this library so I don't know if this issue will be resolved any time soon. Though someone may already have forked the library and made the changes

tylerjames avatar Jun 16 '21 21:06 tylerjames

So, new API changes have come with iOS 15 into the CoreBluetooth framework, and those causes the library to fail the compilation. The changes are related to nullability:

iOS 14.X

CBService
unowned(unsafe) var peripheral: CBPeripheral { get }

CBCharacteristic
unowned(unsafe) var service: CBService { get }

CBDescriptor
unowned(unsafe) var characteristic: CBCharacteristic { get }

iOS 15.X

CBService
weak var peripheral: CBPeripheral? { get }

CBCharacteristic
weak var service: CBService? { get }

CBDescriptor
weak var characteristic: CBCharacteristic? { get }

The main affected classes are:

Source/CentralManagerRestoredState.swift

public var services: [Service] {
    let objects = restoredStateData[CBCentralManagerRestoredStateScanServicesKey] as? [AnyObject]
    guard let arrayOfAnyObjects = objects else { return [] }
    #if swift(>=4.1)
    let cbServices = arrayOfAnyObjects.compactMap { $0 as? CBService }
    #else
    let cbServices = arrayOfAnyObjects.flatMap { $0 as? CBService }
    #endif

    return cbServices.map { Service(peripheral: centralManager.retrievePeripheral(for: $0.peripheral),
                                    service: $0) }
}

This one could be solved by filtering the ones that are not nil:

public var services: [Service] {
    let objects = restoredStateData[CBCentralManagerRestoredStateScanServicesKey] as? [AnyObject]
    guard let arrayOfAnyObjects = objects else { return [] }
    #if swift(>=4.1)
    let cbServices = arrayOfAnyObjects.compactMap { $0 as? CBService }
    #else
    let cbServices = arrayOfAnyObjects.flatMap { $0 as? CBService }
    #endif

    return cbServices
        .filter { $0.peripheral != nil }
        .map {
            Service(peripheral: centralManager.retrievePeripheral(for: $0.peripheral!), service: $0)
        }
}

Source/Characteristic.swift

convenience init(characteristic: CBCharacteristic, peripheral: Peripheral) {
    let service = Service(peripheral: peripheral, service: characteristic.service)
    self.init(characteristic: characteristic, service: service)
}

Source/Descriptor.swift

convenience init(descriptor: CBDescriptor, peripheral: Peripheral) {
    let service = Service(peripheral: peripheral, service: descriptor.characteristic.service)
    let characteristic = Characteristic(characteristic: descriptor.characteristic, service: service)
    self.init(descriptor: descriptor, characteristic: characteristic)
}

These last two might be a little bit trickier since we require not nullable parameters in Service and Characteristic. Making them optional have some side effects.

What do you think about that @mpiechocki?

XabierGoros avatar Jul 01 '21 20:07 XabierGoros

Adding @minixT to please the issue to shed us some light here.

XabierGoros avatar Jul 08 '21 21:07 XabierGoros

@minixT or @mpiechocki are you able to have a look at the PR?

chamira-at avatar Sep 06 '21 11:09 chamira-at

@chamira-at I don't know if I will have time to look at it thoroughly, sorry. I think it's not clear if we will be able to maintain this library whatsoever, unfortunately :( I can try to take a look in some spare time but I cannot guarantee if it's going to be this week, next week or ever :(

mpiechocki avatar Sep 06 '21 11:09 mpiechocki

@mpiechocki Understandable that you guys will not be able to promise anything. Could this be considered grounds to move the project to the @abandonware organisation, so that the community may more effectively be able to solve the issues? iOS 15 is probably right around the corner (read: 7-14 days), so even a start of defaulting to moving it to abandonware would be helpful to a lot of people.

I highly appreciate you guys' work on this! It's been amazing using the project, and I'd hate to see it die, hence the suggestion.

DaBs avatar Sep 08 '21 12:09 DaBs

What’s the workaround? How can we fix this just for our code to compile?

eddy93 avatar Sep 23 '21 14:09 eddy93

There are forks that have already applied the necessary changes for you to use in the meantime. You could fork from one of those and come back to the original if/when it's ever updated:

Try this one pod 'RxBluetoothKit', :git => 'https://github.com/i-mobility/RxBluetoothKit.git', :tag => '7.0.2'

tylerjames avatar Sep 23 '21 14:09 tylerjames

@tylerjames I tried to update pod with 7.0.2 tag but couldn't install

`

Pre-downloading: `RxBluetoothKit` from `https://github.com/i-mobility/RxBluetoothKit.git`, tag `7.0.2`
[!] CocoaPods could not find compatible versions for pod "RxSwift":
  In snapshot (Podfile.lock):
    RxSwift (= 5.1.3, ~> 5, ~> 5.0, ~> 5.1)

  In Podfile:
    RxBluetoothKit (from `https://github.com/i-mobility/RxBluetoothKit.git`, tag `7.0.2`) was resolved to 7.0.0, which depends on
      RxSwift (~> 6.0)

    RxSwift

Specs satisfying the `RxSwift, RxSwift (= 5.1.3, ~> 5, ~> 5.0, ~> 5.1), RxSwift (~> 6.0)` dependency were found, but they required a higher minimum deployment target.

`

I changed platform :ios, '10.0' to 11 ,12,13,14,15 but didn't work

hwikang avatar Nov 03 '21 03:11 hwikang

Hello @mpiechocki, have you guys considered what @DaBs suggested about moving the project to the community? It's been a while since iOS 15 came out, and it's pretty bad not to keep great projects like this up to date with blocker issues like this among other things. As he also mentions, I'd also thank a lot Polidea for what it did opening this great library to us.

XabierGoros avatar Nov 03 '21 07:11 XabierGoros

@hwikang

You need to make sure your other dependencies like RxSwift is also on 6.0+

you can use pod 'RxSwift', '>= 6.0' instead of pod 'RxSwift'

You might also need to update your other dependencies that relies on RxSwift (RxSwiftExt, RxCocoa, etc..) to the latest version.

odemiral avatar Nov 03 '21 22:11 odemiral

so bad

gzzlit avatar Nov 09 '21 01:11 gzzlit

@mpiechocki any updates?

Serg-Pogrebnyak avatar Feb 03 '22 11:02 Serg-Pogrebnyak

Any updates ?

yusufonderd avatar Jul 22 '22 10:07 yusufonderd

@minixT @mpiechocki

Serg-Pogrebnyak avatar Jul 22 '22 10:07 Serg-Pogrebnyak