I’m working to create a minimal MonoTouch binding for the Applifier Obj-C API. It contains this method for init:
+ (Applifier *)initWithApplifierID:(NSString *)applifierID withWindow:(UIWindow *)window
supportedOrientations:(UIDeviceOrientation)orientationsToSupport, ...NS_REQUIRES_NIL_TERMINATION;
Following the instructions in the binding docs for variadic parameter methods, I came up with this interface method:
[Static]
[Export ("initWithApplifierId:withWindow:supportedOrientations:"), Internal]
void InitWithApplifierId (string applifierID, UIWindow withWindow,
UIDeviceOrientation supportedOrientations, IntPtr orientationsPtr);
and this public method in my extension
public static Applifier InitWithApplifierId(string applifierId, UIWindow window,
params UIDeviceOrientation[] supportedOrientations)
{
if (supportedOrientations == null)
throw new ArgumentNullException ("supportedOrientations");
var pNativeArr = Marshal.AllocHGlobal(supportedOrientations.Length * IntPtr.Size);
for (int i = 1; i < supportedOrientations.Length; ++i) {
Marshal.WriteIntPtr (pNativeArr, (i - 1) * IntPtr.Size,
supportedOrientations[i].Handle);
}
// Null termination
Marshal.WriteIntPtr (pNativeArr, (supportedOrientations.Length - 1) * IntPtr.Size,
IntPtr.Zero);
Applifier.InitWithApplifierId(applifierId, window, supportedOrientations[0],
pNativeArr);
Marshal.FreeHGlobal(pNativeArr);
}
However, UIDeviceOrientation is an enum instead of an object, so there is no Handle to write. I’m very new to objective-c and fairly new to C# (my project actually interfaces with MonoTouch through IKVM; my expertise is in Java). I took a stab at doing a naive Marshal.WriteInt32 of the supportedOrientation[i] itself, but that also failed at compile time.
If it would be easier, there is an overload of this method that I could bind instead:
+ (Applifier *)initWithApplifierID:(NSString *)applifierID withWindow:(UIWindow *)window
supportedOrientationsArray:(NSMutableArray *)orientationsArray;
However, I’m not sure how to bind NSMutableArray either 🙂
One solution is to bind the second method you highlight
And now you can use that ctor like this
kinda ugly but should work, hope this helps
Alex