Note: this isn't an app for the App Store, so using private API's isn't a concern to me.
I've been trying to toggle Airplane mode off and back on using Xamarin/Monotouch based off this SO question: How to turn on/off airplane mode in IOS 5.1 using private API
I'm having a hard time getting this code to run in monotouch - first thing I tried was to create a native objective C library using a monotouch binding project.
The AppSupport framework is used so my linkwith file is as follows:
[assembly: LinkWith ("libAirplaneModeLib.a", LinkTarget.ArmV7, ForceLoad = true, Frameworks = "AppSupport")]
When I do this, it compiles but I can't reference the namespace from my main project. If I don't include the framework as follows:
[assembly: LinkWith ("libAirplaneModeLib.a", LinkTarget.ArmV7, ForceLoad = true)]
In this case I can reference the namespace, but the main project compiles on linking with:
"_OBJC_CLASS_$_RadiosPreferences", referenced from:
objc-class-ref in libAirplaneModeLib.a(AirplaneModeLib.o)
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
error MT5202: Native linking failed. Please review the build log.
My ApiDefinition file is as follows:
[BaseType(typeof(NSObject))]
public interface AirplaneModeLib
{
[Export("toggleAirplane")]
void ToggleAirplane ();
}
The native library is as follows:
#import "AirplaneModeLib.h"
#import "RadiosPreferences.h"
@implementation AirplaneModeLib
- (void) toggleAirplane {
RadiosPreferences* preferences = [[RadiosPreferences alloc] init];
preferences.airplaneMode = NO;
[preferences synchronize];
preferences.airplaneMode = YES;
[preferences synchronize];
[preferences release];
}
@end
Is there a better or easier way to do this? If not, can anyone suggest what I'm doing wrong with my current approach?