c# - 切换飞行模式 monotouch xamarin

标签 c# objective-c xamarin.ios xamarin

注意:这不是 App Store 的应用程序,因此我不关心使用私有(private) API。

我一直在尝试根据这个 SO 问题使用 Xamarin/Monotouch 关闭和重新打开飞行模式:How to turn on/off airplane mode in IOS 5.1 using private API

我很难让这段代码在 monotuch 中运行 - 我尝试的第一件事是使用 monotuch 绑定(bind)项目创建一个 native Objective-C 库。

使用了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

是否有更好或更简单的方法来做到这一点?如果没有,谁能建议我目前的方法做错了什么?

最佳答案

看来我已经解决了。出于某种原因,绑定(bind)项目无法引用 AppSupport 框架(或者可以,通过某种我不知道的方法)

在我的主项目中,我手动添加了额外的构建参数

-gcc_flags "-F /path/to/framework -framework AppSupport"

现在可以正常编译了。仍然没有切换飞行模式,但我想这是一个单独的问题......

看起来即使这段代码可以运行,它也不会切换飞行模式。据我所知,在 iOS 5+ 的非越狱设备上无法做到这一点。

关于c# - 切换飞行模式 monotouch xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501923/

相关文章:

c# - 正则表达式允许一组重复不同时间的字符

iphone - objective-c 中的SimpleDateFormat解析时间函数

security - 如何安全地存储公钥/私钥

c# - 使用 @@IDENTITY/scope_identity() 时插入 2 行而不是 1 行

c# - 'Lucene.Net.Store.FSDirectory' 的类型初始值设定项抛出异常

ios - UITableView 方法在 ViewDidLoad 之前调用

c# - 将标准 C# 转换为符合 MonoTouch 的代码

android - 找出 Xamarin 应用随机崩溃的原因

c# - 信号量异常 - 将指定的计数添加到信号量会导致它超过其最大计数

Objective-C Lion 全屏使用所有显示器