nst/iOS-Runtime-Headers

Using private headers in Swift

Opened this issue · 6 comments

Hi!

I'm trying to use a private header (BluetoothManager) in a Swift 3 project, but when I try to use any of the methods, the build fails with the following error:

Undefined symbols for architecture armv7: "_OBJC_CLASS_$_BluetoothManager", referenced from: objc-class-ref in BluetoothViewController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I included the headers in a bridging_header file:

`#ifndef Demo_Bridging_Header_h
#define Demo_Bridging_Header_h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "BluetoothDevice.h"
#import "BluetoothManager.h"

#endif`

But it still does not work. The project compiles until I use any of the methods. Now i'm trying to load the library from a Swift file using this function:

func loadBluetoothFramework() { self.bluetoothLibHandle = dlopen("/System/Library/PrivateFrameworks/BluetoothManager.framework/BluetoothManager", RTLD_NOW) let bm = NSClassFromString("BluetoothManager") as! BluetoothManager.Type //let btManager: BluetoothManager = bm.sharedInstance() as! BluetoothManager }

I also tried to load the library from a 100% Objective-C project and It works perfectly but when i try to do the same with swift, it crashes.

Am I doing anything wrong?

Thanks for help! ;)

Same issue here, have you solved?

Yes! but i don't know how i did it 😆 I just deleted all the files, and then i tried to add the again and the problem was solved.

If you are having problems with the same framework (BluetoothManager) you can check this repository https://github.com/michaeldorner/BeeTee, the owner uploaded a new version two days ago and it is fully written in swift ;)

Thank you, it seems we need wrap all APIs in OBJ-C.

@cybertk Yeah! the problem is that now i'm able to find, connect and disconnect bluetooth devices, but i can's send and/or receive any information :S

@llKoull Would you be willing to share your code for connecting and disconnecting Bluetooth devices? I have been able to use the BeeTee sample project to discover devices but I am having problems when trying to import the connect/connectDevice methods. Thanks!

Hello @JUSTINMKAUFMAN !

I finally abandoned my project and I changed the bluetooth chip by a BLE one. I think that is not posible to communicate the device even using these libraries 😟