Xamarin绑定在设备上失败但在模拟器中工作

时间:2014-09-30 18:39:32

标签: ios binding xamarin.ios xamarin

我创建了一个带有一个函数的Objective-C库。标题定义为:

@interface StarIOFunctions : NSObject {

}

+ (NSMutableData *) GetDataToSendToPrinter:(UIImage *)image maxWidth:(int)maxWidth drawerKick:(BOOL)drawerKick compressionEnable:(BOOL)compressionEnable;

@end

我为它创建了一个绑定:

[BaseType (typeof (NSObject))]
interface StarIOFunctions {
    [Static, Export ("GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:")]
    NSMutableData GetDataToSendToPrinter (UIImage image, int maxWidth, bool kickDrawer, bool compressionEnable);
}

通过以下方式调用:

        image = UIImage.FromBundle("barcode.png");
        NSMutableData commandsToPrint = StarIOFunctions.GetDataToSendToPrinter(image,576,true,true);

所有在模拟器中工作正常,但是当我发布到设备时,应用程序在尝试使用以下错误调用该函数时崩溃:

2014-09-30 19:10:52.776 DemoApp[280:26219] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x14e787c
2014-09-30 19:11:14.697 DemoApp[280:26219] Unhandled managed exception: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x14e787c (MonoTouch.Foundation.MonoTouchException)
(null)

我已经为设备构建了Objective-C库,并在我的绑定中包含了.a文件。我的链接文件是:

[assembly: LinkWith ("libStarIOFunctions.a", LinkTarget.ArmV7, ForceLoad = true)]

为什么它会在iPad上崩溃但不会在模拟器上崩溃?

修改:构建输出位于http://pastebin.com/mtVgHA6L

编辑2 :我今天刚刚LIPO使用了我的两个版本。所以我的链接现在是:

[assembly: LinkWith ("libStarIOFunctions.a", LinkTarget.Simulator | LinkTarget.ArmV7, ForceLoad = true)]

使用以下设备在模拟器和崩溃中仍能正常工作:

2014-09-30 20:20:50.519 DemoApp[313:35575] +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x140887c
2014-09-30 20:20:50.521 DemoApp[313:35575] MonoTouch: Received unhandled ObjectiveC exception: NSInvalidArgumentException +[StarIOFunctions GetDataToSendToPrinter:maxWidth:drawerKick:compressionEnable:]: unrecognized selector sent to class 0x140887c
libc++abi.dylib: terminate_handler unexpectedly threw an exception

0 个答案:

没有答案