Xamarin.iOS运行时绑定项目错误

时间:2017-05-18 14:25:34

标签: xamarin xamarin.ios xamarin.ios-binding

我最近收到了一个iOS SDK,我试图将其绑定到我的应用中。 我有.a文件,我创建了ApiDefinitions.cs类的.h文件,所有内容都构建完成。但是在运行时,无论我试图调用什么方法或属性,我都会收到类似这样的错误 " Neolane_SDK中的IL代码无效:RegisterDevice(Foundation.NSData,string,Foundation.NSDictionary):IL_0043:stloc.s 4 "

我知道库本身正在按预期工作,因为它也用于本机iOS应用程序。 我只想弄清楚我在Binding项目配置中缺少的内容。

这是与我的.a库关联的源.h文件:

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
//the tag id dedicated to the opening of an app following a notification
#define NL_TRACK_CLICK          @"2"

@interface Neolane_SDK : NSObject {
}

// marketingHost is the hostname of the Neolane marketing instance (i.e. host.neolane.org)
@property (strong, nonatomic) NSString *marketingHost;
// trackingHost is the hostname of the Neolane tracking instance (i.e. tracking.neolane.org)
@property (strong, nonatomic) NSString *trackingHost;
// integrationKey is the integration key as confgured in your Neolane instance
@property (strong, nonatomic) NSString *integrationKey;
// The connection timout in second (default 30.0 seconds)
@property (nonatomic) double requestTimeout;


// Get the Neolane_SDK instance
+ (Neolane_SDK *) getInstance;

// Register a device in the Neolane instance
// @param token the token as received from the didRegisterForRemoteNotificationsWithDeviceToken callback.
// @param userKey the user identifier
// @param additionalParams custom additional parameters
- (void) registerDevice:(NSData *) token :(NSString *) userKey :(NSDictionary *) additionalParams;

// Notify Neolane of the opening of a push message
// @param deliveryId is the Neolane delivery identifier, as received in the push message
// @param broadlogId is the Neolane broadlog identifier, as received in the push message
// @param tagId tag identifier in Neolane server (NL_TRACK_CLICK when opening an app following a notification).
- (void) track:(NSString *) deliveryId :(NSString *) broadlogId :(NSString *) tagId;

// Send tracking information to Neolane
// @param launchOptions object received by the application before the opening of the application
// @param tagId tag identifier in Neolane server (NL_TRACK_CLICK when opening an app following a notification)
- (void) track:(NSDictionary *) launchOptions :(NSString *) tagId;


void displayOptions(NSDictionary * launchOptions);
@end

以下是使用sharpie创建的C#关联界面:smile:

// @interface Neolane_SDK : NSObject
    [BaseType(typeof(NSObject))]
    interface Neolane_SDK
    {
        // @property (nonatomic, strong) NSString * marketingHost;
        [Export("marketingHost", ArgumentSemantic.Strong)]
        string MarketingHost { get; set; }

        // @property (nonatomic, strong) NSString * trackingHost;
        [Export("trackingHost", ArgumentSemantic.Strong)]
        string TrackingHost { get; set; }

        // @property (nonatomic, strong) NSString * integrationKey;
        [Export("integrationKey", ArgumentSemantic.Strong)]
        string IntegrationKey { get; set; }

        // @property (nonatomic) double requestTimeout;
        [Export("requestTimeout")]
        double RequestTimeout { get; set; }

        // +(Neolane_SDK *)getInstance;
        [Static]
        [Export("getInstance")]
        Neolane_SDK Instance { get; }

        // -(void)registerDevice:(NSData *)token :(NSString *)userKey :(NSDictionary *)additionalParams;
        [Export("registerDevice:::")]
        void RegisterDevice(NSData token, string userKey, NSDictionary additionalParams);

        // -(void)track:(NSString *)deliveryId :(NSString *)broadlogId :(NSString *)tagId;
        [Export("track:::")]
        void Track(string deliveryId, string broadlogId, string tagId);

        // -(void)track:(NSDictionary *)launchOptions :(NSString *)tagId;
        [Export("track::")]
        void Track(NSDictionary launchOptions, string tagId);
    }

尽管如此,这里是我的.a文件的LinkWith选项

[assembly: LinkWith("libNeolane_SDK.a", SmartLink = true, ForceLoad = true)]

感谢任何帮助/反馈/经验:)

谢谢!

1 个答案:

答案 0 :(得分:4)

如果您使用的是csc(在Windows上或使用Mono 5.0+的macOS上),请确保在编译器选项中设置启用优化

默认情况下, debug 版本不启用该选项,生成的IL除了不是最佳之外,还会混淆mtouch绑定优化器。

这将在下一个XI版本(10.12)中修复,但在绑定项目中使用/optimize+并不是缺点(你甚至不必将其关闭)。