2

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

我知道库本身按预期工作,因为它也用于原生 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)]

任何帮助/反馈/经验表示赞赏:)

谢谢 !

4

1 回答 1

4

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

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

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

于 2017-05-18T17:02:08.870 回答