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



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

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

这是与我的 .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 :smile 创建的 C# 关联接口:

// @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)]

任何帮助/反馈/经验都值得赞赏:)

谢谢!

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

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

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

最新更新