Runtime Error with Interop Callbacks

Hi All,

I’ve got a problem using delegation/callbacks with Unity and was wondering if anyone had managed this before. I’m trying to build a Bluetooth plugin and am trying to rely on delegation and callbacks for connection events as opposed to resorting to polling the connection status. An example of what my design pattern looks like:

Obj-C:

//Relevant parts of Bluetooth.h  Bluetooth.mm

extern "C" {
void (*OnPeerConnect)(const char *);
void SetPeerConnectDelegate(void (*del)(const char *)) {
	OnPeerConnect = del;
}
}

@implementation SessionDelegate
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
	switch(state) {
		case GKPeerStateConnected:
			OnPeerConnect([peerID UTF8String]);
			break;
	}
}
@end

C#:

//Bluetooth.cs

private delegate void PeerConnectDelegate(string peerID);
protected abstract void OnPeerConnect(string peerID);

[DllImport("__Internal")]
private static extern void SetPeerConnectDelegate(PeerConnectDelegate del);

public Bluetooth(ConnectionType type, string displayName, string sessionName) {
	/*...*/
	SetPeerConnectDelegate(OnPeerConnect);
	/*...*/
}
//TestBluetooth.cs

private bool connected = false;
public bool Connected {
	get {
		return connected;
	}
}

protected override void OnPeerConnect(string peerID) {
	connected = true;
}

This all compiles and installs without issue. However, on run, I get the following:

-> applicationDidBecomeActive()
Listening on port 59660
Attempting to JIT compile method '(wrapper native-to-managed) TestBluetooth:OnPeerConnect (intptr)' while running with --aot-only.
Program received signal:  “SIGABRT”.

I’m at a loss as to why I’m getting a SIGABRT (I’m in pretty new territory here with interop services). Can anyone shed any light on this or offer any suggestions?

Bumping for justice.

was mentioned by a dev (think mantasp) that you can’t use callbacks ↔ delegate on the iphone.

But I can’t remember the exact reason anymore, sorry.

If anyone can remember the post that’d be greatly appreciated. Thanks.

it was actually a thread calling unity functions from the xcode side.