When I access static property SharedController
, the value is null, but the API Definition generated by Objective Sharpie only provides a getter.
BBDeviceController
is instantiated, but the SharedController
property on it is null. Because it only has a getter, I do not believe I am able to instantiate the property in code. From what I can tell, SharedController
is not being initialized in BBDeviceController
's constructor. I am unsure if BBDeviceController
is a static class or just follows the singleton design pattern, but either way, newing up that class is not the solution.
BBDeviceController.h
@interface BBDeviceController : NSObject {
NSObject <BBDeviceControllerDelegate>* delegate;
BOOL debugLogEnabled;
BOOL detectAudioDevicePlugged;
}
@property (nonatomic, weak) NSObject <BBDeviceControllerDelegate>* delegate;
@property (nonatomic, getter=isDebugLogEnabled, setter=setDebugLogEnabled:) BOOL debugLogEnabled;
@property (nonatomic, getter=isDetectAudioDevicePlugged, setter=setDetectAudioDevicePlugged:) BOOL detectAudioDevicePlugged;
+ (BBDeviceController *)sharedController;
Resulting API Definition (APIDefinition.cs
)
[BaseType(typeof(NSObject))]
[Protocol]
interface BBDeviceController
{
...
// +(BBDeviceController *)sharedController;
[Static]
[Export("sharedController")]
BBDeviceController SharedController { get; }
...
}
Call from project's view controller
public BBDeviceController bbDeviceController;
public override void ViewDidLoad()
{
base.ViewDidLoad();
bbDeviceController = BBDeviceController.SharedController;
ConnectDevice();
}
private void ConnectDevice()
{
bbDeviceController.StartBTScan(new string[] { DEVICE_NAME }, 60);
}
From the documentation for the objective C library, you use sharedController
like this:
[[BBDeviceController sharedController] setDelegate:self];
When trying to do the C# equivalent, I get an error because SharedController
is null.
Something else that may be of interest is that the SharedController
definition in the resulting API Definitions file was flagged with [Verify(MethodToProperty)]
, and I manually had to add [Static]
in order to access it from code.