我已成功创建更新的ZBar MonoTouch绑定DLL,following up on this answer here from a while ago,使用更新的[Field]绑定来绑定静态NSStrings(以前我只是复制了NSString的值绑定DLL)。MonoTouch绑定到NSString在发布版本中返回null
绑定dll编译正常(编译为发布模式)。
而从我的应用程序使用绑定ZBar.dll在Debug版本中工作正常,从本机库返回正确的NSString值。但是在Release版本中,它始终返回null。
请注意,我已将链接器行为设置为剥离调试版和发布版的所有程序集,因此与链接器剥离任何内容无关。
我试着关闭发布的LLVM编译器,它仍然在发布版本中返回null。然而,在Release版本中启用调试会修复它(显然不是解决方案)。
继承人的绑定代码:
[Static]
interface ZBarSDK
{
// extern NSString* const ZBarReaderControllerResults;
[Field ("ZBarReaderControllerResults", "__Internal")]
NSString BarcodeResultsKey { get; }
}
而这里的反编译IL(据MonoDevelop中):
namespace ZBar
{
public static class ZBarSDK
{
[CompilerGenerated]
private static NSString _BarcodeResultsKey;
[CompilerGenerated]
private static readonly IntPtr __Internal_libraryHandle = Dlfcn.dlopen(null, 0);
public static NSString BarcodeResultsKey
{
get
{
if (ZBarSDK._BarcodeResultsKey == null)
{
ZBarSDK._BarcodeResultsKey = Dlfcn.GetStringConstant(ZBarSDK.__Internal_libraryHandle, "ZBarReaderControllerResults");
}
return ZBarSDK._BarcodeResultsKey;
}
}
}
}
的MonoTouch:6.0.10
你确定你需要FieldAttribute的“__Internal”第二个参数吗? – 2013-03-01 12:00:40
@StephaneDelcroix是的,根据[绑定文档(字段部分)](http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries#37-binding-fields):_如果您要静态链接,没有要绑定的库,因此您需要使用__Internal name_ – Tyson 2013-03-01 12:16:20
@StephaneDelcroix此外,它在启用调试模式时工作。你会认为这样会破坏它的所有情况。 – Tyson 2013-03-01 12:18:34