Closed wescur88 closed 6 years ago
Hi,
Could you provide us with a small test case to reproduce this issue?
using System; using System.Collections.Generic; using System.Linq; using CoreLocation; using Foundation; using MTBeaconPlusBinding; using RhythmBeacon.iOS; using Xamarin.Forms;
[assembly: Dependency(typeof(iBeacon))] namespace RhythmBeacon.iOS { public class iBeacon : IiBeacon, IDisposable { CLLocationManager locationMgr = new CLLocationManager(); CLBeaconRegion region = new CLBeaconRegion(new NSUuid("FDA50693-A4E2-4FB1-AFCF-C6EB07647825"), "com.enovate.rtls");
MTCentralManager mtManager = null;
List<KeyValuePair<Beacon, MTPeripheral>> beaconPeriphList = new List<KeyValuePair<Beacon, MTPeripheral>>();
public bool IsScanning { get; set; } = false;
public event EventHandler BeaconRanged;
public iBeacon()
{
locationMgr.RequestWhenInUseAuthorization();
locationMgr.DidRangeBeacons += LocationMgr_DidRangeBeacons;
locationMgr.RangingBeaconsDidFailForRegion += LocationMgr_RangingBeaconsDidFailForRegion;
mtManager = MTCentralManager.SharedInstance();
}
private void LocationMgr_RangingBeaconsDidFailForRegion(object sender, CLRegionBeaconsFailedEventArgs e)
{
}
private void LocationMgr_DidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
{
BeaconRanged?.Invoke(this, new BeaconsRangededArgs(e.Beacons, Device.RuntimePlatform));
}
~iBeacon()
{
locationMgr = null;
region = null;
}
public void StartScan()
{
//locationMgr.StartMonitoring(region);
//locationMgr.StartRangingBeacons(region);
IsScanning = true;
mtManager.StartScan((periperials)=> {
BeaconRanged?.Invoke(this, new BeaconsRangededArgs(periperials, Device.RuntimePlatform));
});
}
public void StopScan()
{
locationMgr.StopMonitoring(region);
locationMgr.StopRangingBeacons(region);
IsScanning = false;
mtManager.StopScan();
}
public void FillBeacon(Beacon beacon, object ibeacon)
{
//CLBeacon ib = (CLBeacon)ibeacon;
MTPeripheral periph = (MTPeripheral)ibeacon;
MTFrameHandler framer = periph.Framer;
string name = framer.Name; // name of device, may nil
nint rssi = framer.Rssi; // rssi
nint battery = framer.Battery; // battery,may nil
string mac = framer.Mac; // mac address,may nil
MinewFrame[] frames = framer.AdvFrames; // all data frames of device(such as:iBeacon,UID,URL...)
foreach(MinewFrame frame in frames)
{
switch(frame.FrameType)
{
case FrameType.iBeacon:
MinewiBeacon mb = (MinewiBeacon)frame;
beacon.Major = (int)mb.Major;
beacon.Minor = (int)mb.Minor;
break;
case FrameType.Uid:
MinewUID uid = (MinewUID)frame;
beacon.ProximityUuid = uid.NamespaceId;
break;
case FrameType.DeviceInfo:
MinewDeviceInfo di = (MinewDeviceInfo)frame;
break;
case FrameType.Connectable:
int i = 0;
break;
case FrameType.Tlm:
int tlm = 0;
break;
case FrameType.AccSensor:
int acc = 0;
break;
case FrameType.LightSensor:
int ls = 0;
break;
case FrameType.Unknown:
int j = 0;
break;
}
}
//beacon.Major = (int)ib.Major;
//beacon.Minor = (int)ib.Minor;
//beacon.ProximityUuid = ib.ProximityUuid.ToString();
//if (ib.Accuracy != -1)
//{
// beacon.Accuracy = ib.Accuracy;
// beacon.Proximity = (int)ib.Proximity;
// beacon.Rssi = (int)ib.Rssi;
// beacon.LastUpdate = DateTime.Now;
//}
//else
//{
//}
var existing = beaconPeriphList.FirstOrDefault(bp => bp.Key == beacon);
var def = default(KeyValuePair<Beacon, MTPeripheral>);
if (existing.Equals(def))
beaconPeriphList.Add(new KeyValuePair<Beacon, MTPeripheral>(beacon, periph));
}
public void Dispose()
{
locationMgr.DidRangeBeacons -= LocationMgr_DidRangeBeacons;
locationMgr.RangingBeaconsDidFailForRegion -= LocationMgr_RangingBeaconsDidFailForRegion;
locationMgr.Dispose();
region.Dispose();
}
public void Connect(Beacon beacon)
{
MTPeripheral periph = beaconPeriphList.First(bp => bp.Key == beacon).Value;
periph.Connector.StatusChangedHandler += (conStatus, error)=> {
var di = periph.Connector.InfoDict;
var mac = periph.Connector.MacString;
var connectable = periph.Connector.Connectable;
var version = periph.Connector.Version;
var passStat = periph.Connector.PasswordStatus;
var conFeature = periph.Connector.Feature;
var slotAttitude = conFeature.SlotAtitude;
var featureSupport = conFeature.FeatureSupported;
var supFrames = conFeature.SupportedFrames;
var supTxpower = conFeature.SupportedTxpowers;
if (conStatus == ConnectionStatus.Disconnected)
mtManager.StartScan((periperials) => {
BeaconRanged?.Invoke(this, new BeaconsRangededArgs(periperials, Device.RuntimePlatform));
});
};
mtManager.ConnectToPeriperal(periph, (passBlock)=> {
passBlock("minew123");
});
}
}
}
// // Auto-generated from generator.cs, do not edit // // We keep references to objects, so warning 414 is expected
using System; using System.Drawing; using System.Diagnostics; using System.ComponentModel; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using UIKit; using GLKit; using Metal; using MapKit; using Photos; using ModelIO; using SceneKit; using Contacts; using Security; using Messages; using AudioUnit; using CoreVideo; using CoreMedia; using QuickLook; using CoreImage; using SpriteKit; using Foundation; using CoreMotion; using ObjCRuntime; using AddressBook; using MediaPlayer; using GameplayKit; using CoreGraphics; using CoreLocation; using AVFoundation; using NewsstandKit; using FileProvider; using CoreAnimation; using CoreFoundation;
namespace ObjCRuntime {
[CompilerGenerated]
static partial class Trampolines {
[DllImport ("/usr/lib/libobjc.dylib")]
static extern IntPtr _Block_copy (IntPtr ptr);
[DllImport ("/usr/lib/libobjc.dylib")]
static extern void _Block_release (IntPtr ptr);
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTCOperationBlock))]
internal delegate void DMTCOperationBlock (IntPtr block, bool arg0, IntPtr arg1);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTCOperationBlock {
static internal readonly DMTCOperationBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTCOperationBlock))]
static unsafe void Invoke (IntPtr block, bool arg0, IntPtr arg1) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTCOperationBlock) (descriptor->Target);
if (del != null)
del (arg0, Runtime.GetNSObject<NSError> (arg1));
}
} /* class SDMTCOperationBlock */
internal class NIDMTCOperationBlock {
IntPtr blockPtr;
DMTCOperationBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTCOperationBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTCOperationBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTCOperationBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTCOperationBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTCOperationBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTCOperationBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (bool arg0, NSError arg1)
{
invoker (blockPtr, arg0, arg1 == null ? IntPtr.Zero : arg1.Handle);
}
} /* class NIDMTCOperationBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTHTHistoryBlock))]
internal delegate void DMTHTHistoryBlock (IntPtr block, IntPtr arg0, nuint arg1);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTHTHistoryBlock {
static internal readonly DMTHTHistoryBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTHTHistoryBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0, nuint arg1) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTHTHistoryBlock) (descriptor->Target);
if (del != null)
del ( Runtime.GetNSObject<MTBeaconPlusBinding.MTSensorData> (arg0), (global::MTBeaconPlusBinding.EndStatus) (ulong) arg1);
}
} /* class SDMTHTHistoryBlock */
internal class NIDMTHTHistoryBlock {
IntPtr blockPtr;
DMTHTHistoryBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTHTHistoryBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTHTHistoryBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTHTHistoryBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTHTHistoryBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTHTHistoryBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTHTHistoryBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (global::MTBeaconPlusBinding.MTSensorData arg0, global::MTBeaconPlusBinding.EndStatus arg1)
{
invoker (blockPtr, arg0 == null ? IntPtr.Zero : arg0.Handle, (nuint) (UInt64) arg1);
}
} /* class NIDMTHTHistoryBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordRequireBlock))]
internal delegate void DMTPasswordRequireBlock (IntPtr block, IntPtr arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTPasswordRequireBlock {
static internal readonly DMTPasswordRequireBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTPasswordRequireBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTPasswordRequireBlock) (descriptor->Target);
if (del != null)
del ((MTBeaconPlusBinding.MTPasswordBlock) Marshal.GetDelegateForFunctionPointer (arg0, typeof (MTBeaconPlusBinding.MTPasswordBlock)));
}
} /* class SDMTPasswordRequireBlock */
internal class NIDMTPasswordRequireBlock {
IntPtr blockPtr;
DMTPasswordRequireBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTPasswordRequireBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTPasswordRequireBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTPasswordRequireBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTPasswordRequireBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTPasswordRequireBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTPasswordRequireBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke ([BlockProxy (typeof (ObjCRuntime.Trampolines.NIDMTPasswordBlock))]global::MTBeaconPlusBinding.MTPasswordBlock arg0)
{
BlockLiteral *block_ptr_arg0;
BlockLiteral block_arg0;
block_arg0 = new BlockLiteral ();
block_ptr_arg0 = &block_arg0;
block_arg0.SetupBlockUnsafe (Trampolines.SDMTPasswordBlock.Handler, arg0);
invoker (blockPtr, (IntPtr) block_ptr_arg0);
block_ptr_arg0->CleanupBlock ();
}
} /* class NIDMTPasswordRequireBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTScanBlock))]
internal delegate void DMTScanBlock (IntPtr block, IntPtr arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTScanBlock {
static internal readonly DMTScanBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTScanBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTScanBlock) (descriptor->Target);
if (del != null)
del (NSArray.ArrayFromHandle<global::MTBeaconPlusBinding.MTPeripheral> (arg0));
}
} /* class SDMTScanBlock */
internal class NIDMTScanBlock {
IntPtr blockPtr;
DMTScanBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTScanBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTScanBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTScanBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTScanBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTScanBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTScanBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (global::MTBeaconPlusBinding.MTPeripheral[] arg0)
{
var nsa_arg0 = arg0 == null ? null : NSArray.FromNSObjects (arg0);
invoker (blockPtr, nsa_arg0 == null ? IntPtr.Zero : nsa_arg0.Handle);
if (nsa_arg0 != null)
nsa_arg0.Dispose ();
}
} /* class NIDMTScanBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTStatusChangeBlock))]
internal delegate void DMTStatusChangeBlock (IntPtr block, nint arg0, IntPtr arg1);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTStatusChangeBlock {
static internal readonly DMTStatusChangeBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTStatusChangeBlock))]
static unsafe void Invoke (IntPtr block, nint arg0, IntPtr arg1) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTStatusChangeBlock) (descriptor->Target);
if (del != null)
del ((global::MTBeaconPlusBinding.ConnectionStatus) (long) arg0, Runtime.GetNSObject<NSError> (arg1));
}
} /* class SDMTStatusChangeBlock */
internal class NIDMTStatusChangeBlock {
IntPtr blockPtr;
DMTStatusChangeBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTStatusChangeBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTStatusChangeBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTStatusChangeBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTStatusChangeBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTStatusChangeBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTStatusChangeBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (global::MTBeaconPlusBinding.ConnectionStatus arg0, NSError arg1)
{
invoker (blockPtr, (nint) (Int64) arg0, arg1 == null ? IntPtr.Zero : arg1.Handle);
}
} /* class NIDMTStatusChangeBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTTriggerWroteBlock))]
internal delegate void DMTTriggerWroteBlock (IntPtr block, bool arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTTriggerWroteBlock {
static internal readonly DMTTriggerWroteBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTTriggerWroteBlock))]
static unsafe void Invoke (IntPtr block, bool arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTTriggerWroteBlock) (descriptor->Target);
if (del != null)
del (arg0);
}
} /* class SDMTTriggerWroteBlock */
internal class NIDMTTriggerWroteBlock {
IntPtr blockPtr;
DMTTriggerWroteBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTTriggerWroteBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTTriggerWroteBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTTriggerWroteBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTTriggerWroteBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTTriggerWroteBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTTriggerWroteBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (bool arg0)
{
invoker (blockPtr, arg0);
}
} /* class NIDMTTriggerWroteBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAErrorBlock))]
internal delegate void DOTAErrorBlock (IntPtr block, IntPtr arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDOTAErrorBlock {
static internal readonly DOTAErrorBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DOTAErrorBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.OTAErrorBlock) (descriptor->Target);
if (del != null)
del ( Runtime.GetNSObject<NSError> (arg0));
}
} /* class SDOTAErrorBlock */
internal class NIDOTAErrorBlock {
IntPtr blockPtr;
DOTAErrorBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDOTAErrorBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DOTAErrorBlock> ();
}
[Preserve (Conditional=true)]
~NIDOTAErrorBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.OTAErrorBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAErrorBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDOTAErrorBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (NSError arg0)
{
invoker (blockPtr, arg0 == null ? IntPtr.Zero : arg0.Handle);
}
} /* class NIDOTAErrorBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAProgressBlock))]
internal delegate void DOTAProgressBlock (IntPtr block, float arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDOTAProgressBlock {
static internal readonly DOTAProgressBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DOTAProgressBlock))]
static unsafe void Invoke (IntPtr block, float arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.OTAProgressBlock) (descriptor->Target);
if (del != null)
del (arg0);
}
} /* class SDOTAProgressBlock */
internal class NIDOTAProgressBlock {
IntPtr blockPtr;
DOTAProgressBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDOTAProgressBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DOTAProgressBlock> ();
}
[Preserve (Conditional=true)]
~NIDOTAProgressBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.OTAProgressBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAProgressBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDOTAProgressBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (float arg0)
{
invoker (blockPtr, arg0);
}
} /* class NIDOTAProgressBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAStateBlock))]
internal delegate void DOTAStateBlock (IntPtr block, nint arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDOTAStateBlock {
static internal readonly DOTAStateBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DOTAStateBlock))]
static unsafe void Invoke (IntPtr block, nint arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.OTAStateBlock) (descriptor->Target);
if (del != null)
del ((global::MTBeaconPlusBinding.OTAState) (long) arg0);
}
} /* class SDOTAStateBlock */
internal class NIDOTAStateBlock {
IntPtr blockPtr;
DOTAStateBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDOTAStateBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DOTAStateBlock> ();
}
[Preserve (Conditional=true)]
~NIDOTAStateBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.OTAStateBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAStateBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDOTAStateBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (global::MTBeaconPlusBinding.OTAState arg0)
{
invoker (blockPtr, (nint) (Int64) arg0);
}
} /* class NIDOTAStateBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.PowerStateBlock))]
internal delegate void DPowerStateBlock (IntPtr block, nuint arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDPowerStateBlock {
static internal readonly DPowerStateBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DPowerStateBlock))]
static unsafe void Invoke (IntPtr block, nuint arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.PowerStateBlock) (descriptor->Target);
if (del != null)
del ((global::MTBeaconPlusBinding.PowerState) (ulong) arg0);
}
} /* class SDPowerStateBlock */
internal class NIDPowerStateBlock {
IntPtr blockPtr;
DPowerStateBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDPowerStateBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DPowerStateBlock> ();
}
[Preserve (Conditional=true)]
~NIDPowerStateBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.PowerStateBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.PowerStateBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDPowerStateBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (global::MTBeaconPlusBinding.PowerState arg0)
{
invoker (blockPtr, (nuint) (UInt64) arg0);
}
} /* class NIDPowerStateBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordBlock))]
internal delegate void DMTPasswordBlock (IntPtr block, IntPtr arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTPasswordBlock {
static internal readonly DMTPasswordBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTPasswordBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTPasswordBlock) (descriptor->Target);
if (del != null)
del (NSString.FromHandle (arg0));
}
} /* class SDMTPasswordBlock */
internal class NIDMTPasswordBlock {
IntPtr blockPtr;
DMTPasswordBlock invoker;
[Preserve (Conditional=true)]
public unsafe NIDMTPasswordBlock (BlockLiteral *block)
{
blockPtr = _Block_copy ((IntPtr) block);
invoker = block->GetDelegateForBlock<DMTPasswordBlock> ();
}
[Preserve (Conditional=true)]
~NIDMTPasswordBlock ()
{
_Block_release (blockPtr);
}
[Preserve (Conditional=true)]
public unsafe static global::MTBeaconPlusBinding.MTPasswordBlock Create (IntPtr block)
{
if (block == IntPtr.Zero)
return null;
if (BlockLiteral.IsManagedBlock (block)) {
var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTPasswordBlock;
if (existing_delegate != null)
return existing_delegate;
}
return new NIDMTPasswordBlock ((BlockLiteral *) block).Invoke;
}
[Preserve (Conditional=true)]
unsafe void Invoke (string arg0)
{
var nsarg0 = NSString.CreateNative (arg0);
invoker (blockPtr, nsarg0);
NSString.ReleaseNative (nsarg0);
}
} /* class NIDMTPasswordBlock */
}
}
This is the problem block of code. It is generated by the compiler
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)] [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordRequireBlock))] internal delegate void DMTPasswordRequireBlock (IntPtr block, IntPtr arg0);
//
// This class bridges native block invocations that call into C#
//
static internal class SDMTPasswordRequireBlock {
static internal readonly DMTPasswordRequireBlock Handler = Invoke;
[MonoPInvokeCallback (typeof (DMTPasswordRequireBlock))]
static unsafe void Invoke (IntPtr block, IntPtr arg0) {
var descriptor = (BlockLiteral *) block;
var del = (global::MTBeaconPlusBinding.MTPasswordRequireBlock) (descriptor->Target);
if (del != null)
del ((MTBeaconPlusBinding.MTPasswordBlock) Marshal.GetDelegateForFunctionPointer (arg0, typeof (MTBeaconPlusBinding.MTPasswordBlock)));
}
} /* class SDMTPasswordRequireBlock */
Issue resolved. In the MTBeaconPlusBinding project I had to add the [BlockCallback] for this delegate: delegate void MTPasswordRequireBlock(MTPasswordBlock arg0); //old delegate void MTPasswordRequireBlock([BlockCallback] MTPasswordBlock arg0); //new
Steps to Reproduce
Expected Behavior
Return a native delegate
Actual Behavior
System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) MTBeaconPlusBinding.MTPasswordBlock:wrapper_aot_native (object,string)' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.
Environment
Visual Studio 2017 Professional
Build Logs
Example Project (If Possible)