# Runtime Error with Interop Callbacks

**URL:** https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512
**Category:** Mobile
**Tags:** iOS
**Created:** [November 12, 2009, 5:39pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512 "2009-11-12T17:39:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_19988889](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@anon\_19988889](https://discussions.unity.com/u/anon_19988889)
#### Post date: [November 12, 2009, 5:39pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512/1 "2009-11-12T17:39:28Z")

</div>

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:

```auto
//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#:

```auto
//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);
	/*...*/
}

```

```auto
//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:

```auto
-> 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?

---

<div class="post-metadata">

### Author: ![anon\_19988889](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@anon\_19988889](https://discussions.unity.com/u/anon_19988889)
#### Post date: [November 12, 2009, 10:54pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512/2 "2009-11-12T22:54:49Z")

</div>

Bumping for justice.

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [November 12, 2009, 11:20pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512/3 "2009-11-12T23:20:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![anon\_19988889](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@anon\_19988889](https://discussions.unity.com/u/anon_19988889)
#### Post date: [November 12, 2009, 11:31pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512/4 "2009-11-12T23:31:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [November 12, 2009, 11:35pm UTC](https://discussions.unity.com/t/runtime-error-with-interop-callbacks/401512/5 "2009-11-12T23:35:45Z")

</div>

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