注意:这不是一个面向App Store的应用程序,因此对私有API的使用并不会受到我的担忧。
我一直在尝试使用Xamarin/Monotouch切换飞行模式,基于这个SO问题:如何使用私有API在IOS 5.1中打开/关闭飞行模式 我很难让这段代码在monotouch中运行——首先我尝试创建一个本地的Objective C库,使用monotouch绑定项目。
需要使用AppSupport框架,所以我的linkwith文件如下:
当我这样做时,代码可以编译,但是我无法从主项目中引用该命名空间。如果我不像下面这样包含框架:
在这种情况下,我可以引用命名空间,但是主项目在链接时会编译出错。
本地库如下:
有更好或更简单的方法吗?如果没有,有人能建议一下我当前的做法有什么问题吗?
我一直在尝试使用Xamarin/Monotouch切换飞行模式,基于这个SO问题:如何使用私有API在IOS 5.1中打开/关闭飞行模式 我很难让这段代码在monotouch中运行——首先我尝试创建一个本地的Objective C库,使用monotouch绑定项目。
需要使用AppSupport框架,所以我的linkwith文件如下:
[assembly: LinkWith ("libAirplaneModeLib.a", LinkTarget.ArmV7, ForceLoad = true, Frameworks = "AppSupport")]
当我这样做时,代码可以编译,但是我无法从主项目中引用该命名空间。如果我不像下面这样包含框架:
[assembly: LinkWith ("libAirplaneModeLib.a", LinkTarget.ArmV7, ForceLoad = true)]
在这种情况下,我可以引用命名空间,但是主项目在链接时会编译出错。
"_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.
我的ApiDefinition文件如下:
[BaseType(typeof(NSObject))]
public interface AirplaneModeLib
{
[Export("toggleAirplane")]
void ToggleAirplane ();
}
本地库如下:
#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
有更好或更简单的方法吗?如果没有,有人能建议一下我当前的做法有什么问题吗?