From 872dbaa06edcf0c6781eaed6b67f77bc8c093a87 Mon Sep 17 00:00:00 2001 From: David Oliver Date: Tue, 21 May 2019 10:30:03 -0400 Subject: [PATCH 1/2] [iOS] Add MonoPInvokeCallback tag to fix error on device See https://stackoverflow.com/questions/12340113/monotouchbass-dll-application-crash-attempting-to-jit-compile-method-whi --- .../CalcManager/CalculatorManager.Interop.cs | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs b/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs index 5d98e8a3..560803de 100644 --- a/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs +++ b/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs @@ -102,17 +102,28 @@ namespace CalculationManager [DllImport(DllPath)] public static extern CommandType IExpressionCommand_GetCommandType(IntPtr pExpressionCommand); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate IntPtr GetCEngineStringFunc(IntPtr state, IntPtr id); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void BinaryOperatorReceivedFunc(IntPtr state); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SetPrimaryDisplayCallbackFunc(IntPtr state, IntPtr pDisplayStringValue, bool isError); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SetIsInErrorCallbackFunc(IntPtr state, bool isError); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SetParenthesisNumberCallbackFunc(IntPtr state, int parenthesisCount); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void MaxDigitsReachedCallbackFunc(IntPtr state); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void MemoryItemChangedCallbackFunc(IntPtr state, int indexOfMemory); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void OnHistoryItemAddedCallbackFunc(IntPtr state, int addedItemIndex); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void OnNoRightParenAddedCallbackFunc(IntPtr state); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SetExpressionDisplayCallbackFunc(IntPtr state, IntPtr data); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SetMemorizedNumbersCallbackFunc(IntPtr state, int count, IntPtr newMemorizedNumbers); public static GetCEngineStringFunc _getCEngineStringCallback = GetCEngineStringCallback; @@ -128,6 +139,9 @@ namespace CalculationManager public static SetExpressionDisplayCallbackFunc _setExpressionDisplayCallback = SetExpressionDisplayCallback; public static SetMemorizedNumbersCallbackFunc _setMemorizedNumbersCallback = SetMemorizedNumbersCallback; +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(MaxDigitsReachedCallbackFunc))] +#endif public static void MaxDigitsReachedCallback(IntPtr state) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -136,6 +150,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.MaxDigitsReachedCallback"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(MemoryItemChangedCallbackFunc))] +#endif public static void MemoryItemChangedCallback(IntPtr state, int indexOfMemory) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -144,6 +161,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.MemoryItemChangedCallback({indexOfMemory})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(OnHistoryItemAddedCallbackFunc))] +#endif public static void OnHistoryItemAddedCallback(IntPtr state, int addedItemIndex) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -152,6 +172,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.OnHistoryItemAddedCallback({addedItemIndex})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(OnNoRightParenAddedCallbackFunc))] +#endif public static void OnNoRightParenAddedCallback(IntPtr state) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -160,6 +183,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.OnNoRightParenAddedCallback"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(SetExpressionDisplayCallbackFunc))] +#endif public static void SetExpressionDisplayCallback(IntPtr state, IntPtr historyItem) { DebugTrace($"CalculatorManager.SetExpressionDisplayCallback({state}, {historyItem})"); @@ -177,6 +203,9 @@ namespace CalculationManager } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(SetMemorizedNumbersCallbackFunc))] +#endif public static void SetMemorizedNumbersCallback(IntPtr state, int count, IntPtr newMemorizedNumbers) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -193,6 +222,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.SetMemorizedNumbersCallback({string.Join(";", numbers)})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(SetParenthesisNumberCallbackFunc))] +#endif public static void SetParenthesisNumberCallback(IntPtr state, int parenthesisCount) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -201,6 +233,10 @@ namespace CalculationManager DebugTrace($"CalculatorManager.SetParenthesisNumberCallback({parenthesisCount})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(BinaryOperatorReceivedFunc))] +#endif + public static void BinaryOperatorReceivedCallback(IntPtr state) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -209,6 +245,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.BinaryOperatorReceivedCallback"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(SetPrimaryDisplayCallbackFunc))] +#endif public static void SetPrimaryDisplayCallback(IntPtr state, IntPtr pDisplayStringValue, bool isError) { var displayStringValue = PtrToString(pDisplayStringValue); @@ -219,6 +258,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.SetPrimaryDisplayCallback({displayStringValue}, {isError})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(SetIsInErrorCallbackFunc))] +#endif public static void SetIsInErrorCallback(IntPtr state, bool isError) { var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; @@ -227,6 +269,9 @@ namespace CalculationManager DebugTrace($"CalculatorManager.SetIsInErrorCallback({isError})"); } +#if __IOS__ + [ObjCRuntime.MonoPInvokeCallback(typeof(GetCEngineStringFunc))] +#endif public static IntPtr GetCEngineStringCallback(IntPtr state, IntPtr pResourceId) { var provider = GCHandle.FromIntPtr(state).Target as EngineResourceProvider; @@ -321,7 +366,7 @@ namespace CalculationManager public partial class CalculatorManager : ICalcDisplay - { + { private GCHandle _displayCallbackHandle; private GCHandle _resourceProviderHandle; From 7c7f103702a2803526e6eb57736abec0be3b8b78 Mon Sep 17 00:00:00 2001 From: David Oliver Date: Tue, 21 May 2019 10:32:59 -0400 Subject: [PATCH 2/2] [iOS] Add minimum version Required to build to device. --- src/Calculator.iOS/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Calculator.iOS/Info.plist b/src/Calculator.iOS/Info.plist index 6f1c9611..3d4e5835 100644 --- a/src/Calculator.iOS/Info.plist +++ b/src/Calculator.iOS/Info.plist @@ -13,7 +13,7 @@ LSRequiresIPhoneOS MinimumOSVersion - + 9.0 UIDeviceFamily 1