ObjC compatibility

Hi,

I've finally been able to install and build the new API, 3.1.6. However, it doesn't seem fully compatible with an ObjC project, ie. the MetaWear-Swift bridging header doesn't supply the necessary methods in order to actually use the API. I'm wondering if there is continuing support for the ObjC API and, if not, whether compatibility will be improved within the Swift API to support ObjC projects.

Thanks,

--Alex

Comments

  • We are moving away from Obj-C in place of Swift as preferred by Apple.

    Please make sure to use the latest API 3.1.6 which is fully compatible.
    3.1.6 is a Swift wrapper on top of our MetaWear C libraries.

    If you have specific integration issues with 3.1.6, please post your errors with supporting evidence (image/snapshot/screen-grab/code snippet/xcode error).

    Also, please make sure to update XCODE; this could be your issue.

    Thanks,
    -Laura

  • Thanks Laura, my XCode is the latest official release (9.4.1). That isn't the issue. The issue is that the Metawear Swift framework doesn't expose any useful functionality to ObjC. Simply look at the Swift brigding header in the framework. These are the methods actually exposed to ObjC that can be used by an ObjC caller.

    /// Scanner utility, make is simple to start scanning for MetaWear devices without
    /// having to understand all of CoreBluetooth
    SWIFT_CLASS("_TtC8MetaWear15MetaWearScanner")
    @interface MetaWearScanner : NSObject
    - (nonnull instancetype)init SWIFT_UNAVAILABLE;
    + (nonnull instancetype)new SWIFT_DEPRECATED_MSG("-init is unavailable");
    @end
    
    @class CBCentralManager;
    
    @interface MetaWearScanner (SWIFT_EXTENSION(MetaWear)) <CBCentralManagerDelegate>
    - (void)centralManagerDidUpdateState:(CBCentralManager * _Nonnull)central;
    - (void)centralManager:(CBCentralManager * _Nonnull)central didDiscoverPeripheral:(CBPeripheral * _Nonnull)peripheral advertisementData:(NSDictionary<NSString *, id> * _Nonnull)advertisementData RSSI:(NSNumber * _Nonnull)RSSI;
    - (void)centralManager:(CBCentralManager * _Nonnull)central didConnectPeripheral:(CBPeripheral * _Nonnull)peripheral;
    - (void)centralManager:(CBCentralManager * _Nonnull)central didFailToConnectPeripheral:(CBPeripheral * _Nonnull)peripheral error:(NSError * _Nullable)error;
    - (void)centralManager:(CBCentralManager * _Nonnull)central didDisconnectPeripheral:(CBPeripheral * _Nonnull)peripheral error:(NSError * _Nullable)error;
    - (void)centralManager:(CBCentralManager * _Nonnull)central willRestoreState:(NSDictionary<NSString *, id> * _Nonnull)dict;
    @end
    

    You'll see that none of the discovery functionality is actually available. So if you try to use this in ObjC code, you get the following.

    The same applies to the MetaWear class which doesn't expose any useful methods for connecting to the sensor and reading measurements from it. If I'm doing something wrong, please post an ObjC starter project that uses the new API, but I' pretty sure it's not possible given the current API.

    Thanks,

    --Alex

  • Unfortunate Re: Objective-C

    Having the base Swift classes class inherit NSObject (or annotated with @objc) and exporting to bridging header shouldn’t require too much effort and would allow Objective-C to import Swift classes natively. Outside of Apple’s push for Swift, is there any performance or technical issues that prevent those changes for developers with this issue?

    /blee/

  • I’ve also found (with nRF BLE devices, haven’t tested any of your boards yet, but receiving mine today) that depending on iOS and Swift versions, that intermittent weird connection and timeout issues can happen in various circumstances using Swift, but ObjC doesn’t have the same issues. Technically you’d assume that the same underlying stack is used on iOS, but have experienced this enough to try my best to stay away from using Swift for BLE connections until Apple gets that stable. Mostly use Swift for UI controller related stuff because of this. Usually happens after iOS updates or Swift version updates in the past.

    /blee/

  • It's worth noting that the "Swift" MetaWear really isn't Swift. It's only a few Swift classes that provide the barest of interfaces on top of the C++ API.

  • edited November 1

    That is understood. But the C++ SDK (which Swift wraps) doesn’t handle BLE communication. Swift handles the BLE connection and the C++ SDK just handles message packing and functions after connection has been established. And I’ve experienced problems specifically with different versions of Swift on different iOS releases which can make connecting and maintains the connection unstable sometimes, but never from regular ol ObjC with various devices.

    /blee/

  • For anyone that needs to develop in objective-c I would stick to version 2.X of the MetaWear iOS SDK. You can find the docs here: https://mbientlab.com/iosdocs/2/index.html.

    Version 3.X, was never tested with objective-c. We haven't looked, in detail, what it would take for everything to bridge correctly. If you have any forks or pull-requests with this working please let us know and we can look to integrating.

  • @stephen said:
    For anyone that needs to develop in objective-c I would stick to version 2.X of the MetaWear iOS SDK. You can find the docs here: https://mbientlab.com/iosdocs/2/index.html.

    Version 3.X, was never tested with objective-c. We haven't looked, in detail, what it would take for everything to bridge correctly. If you have any forks or pull-requests with this working please let us know and we can look to integrating.

    Thank you Steve.

    /blee/

Sign In or Register to comment.