MonoTouch 绑定到 ObjectiveC 库不起作用 [英] MonoTouch binding to ObjectiveC library not working

查看:43
本文介绍了MonoTouch 绑定到 ObjectiveC 库不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.h:

#import <Foundation/Foundation.h>

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType ;


@interface XLXtifyOptions :NSObject
{
    NSString *xoAppKey;
    BOOL    xoLocationRequired ;
    BOOL    xoBackgroundLocationRequired ;
    BOOL    xoLogging ;
    BOOL    xoMultipleMarkets;
    XLBadgeManagedType xoManageBadge;
}
+ (XLXtifyOptions *)getXtifyOptions;
- (NSString *)getAppKey ;
- (BOOL) isLocationRequired;
- (BOOL) isBackgroundLocationRequired ;
- (BOOL) isLogging ;
- (BOOL) isMultipleMarkets;
- (XLBadgeManagedType)  getManageBadgeType;
- (void)xtLogMessage:(NSString *)header content:(NSString *)message, ...;
@end

.m:

#import "XLXtifyOptions.h"
#import "XtifyGlobal.h"

static  XLXtifyOptions *xXtifyOptions=nil;

@implementation XLXtifyOptions

+ (XLXtifyOptions *)getXtifyOptions
{
    if (xXtifyOptions==nil) {
        xXtifyOptions=[[XLXtifyOptions alloc]init];
    }
    return xXtifyOptions;
}

-(id)init
{
    if (self = [super init]) {        
        xoAppKey=xAppKey;
        xoLocationRequired=xLocationRequired;
        xoBackgroundLocationRequired=xRunAlsoInBackground ;
        xoLogging =xLogging ;
        xoMultipleMarkets=xMultipleMarkets;
        xoManageBadge=xBadgeManagerMethod;

    }
    return self;
}

- (NSString *)getAppKey
{
    return xoAppKey;
}
- (BOOL) isLocationRequired
{
    return xoLocationRequired;
}
- (BOOL) isBackgroundLocationRequired 
{
    return xoBackgroundLocationRequired;
}
- (BOOL) isLogging 
{
    return xoLogging;
}
- (BOOL) isMultipleMarkets
{
    return xoMultipleMarkets;
}
- (XLBadgeManagedType)  getManageBadgeType
{
    return xoManageBadge;
}
- (void)xtLogMessage:(NSString *)header content:(NSString *)format, ... {
    va_list args;
    va_start(args, format);
    if (xoLogging) {
        NSString *prettyFmt=[NSString stringWithFormat:@"%@ %@", header,format];
        NSLogv(prettyFmt, args);
    }
    va_end(args);
}
@end

全局.h:

#define xAppKey @"abc123"

#define xLocationRequired NO

#define xRunAlsoInBackground FALSE    

#define xBadgeManagerMethod XLInboxManagedMethod 

#define xLogging TRUE

#define xMultipleMarkets FALSE

我的绑定定义:

[BaseType (typeof (NSObject))]
public interface XLXtifyOptions {

    [Static]
    [Export ("xtifyOptions")]
    XLXtifyOptions Options { get;}

    [Export ("getAppKey")]
    string GetAppKey ();

    [Export ("isLocationRequired")]
    bool IsLocationRequired ();

    [Export ("isBackgroundLocationRequired")]
    bool IsBackgroundLocationRequired ();

    [Export ("isLogging")]
    bool IsLogging ();

    [Export ("isMultipleMarkets")]
    bool IsMultipleMarkets ();

    [Export ("getManageBadgeType")]
    XLBadgeManagedType GetManageBadgeType ();

    //      [Export ("xtLogMessage:content:...")]
    //      void XtLogMessagecontent... (string header, string message,, );
    //      
}

这些返回空值:

XLXtifyOptions.Options;
new XLXtifyOptions().GetAppKey();

供应商的入门说明:

  XLXtifyOptions *anXtifyOptions=[Options getVendorOptions];
  [[TheirClass get ]initilizeXoptions:anVendorOptions];

我匆忙尝试重命名一些东西,因为我不确定有多少供应商的代码可以粘贴,所以希望我没有混淆问题.

I hastily tried to rename some things because I'm not sure how much of the vendor's code is ok to paste, so hopefully I didn't confuse matters.

这与:绑定#define用作常量有关

更多信息:

如果我在设备而不是模拟器上运行它,我会收到以下错误:

If I run this on a device rather than the simulator, I get the following error:

Unhandled managed exception: Wrapper type 'XtifyPush.XLXtifyOptions' is missing its native ObjectiveC class 'XLXtifyOptions'. 

编辑

re @Stephane:我更新了代码,不再模糊供应商.我绑定的是:http://developer.xtify.com/display/sdk/Getting+Started+with+Apple+Push+Notification+Service,fwiw.我按照您的建议更新了对 getXtifyOptions 的引用,但结果相同.我对你引用的 github 库的了解已经达到了,但我会继续挖掘.

re @Stephane: I updated the code to no longer obscure the vendor. What I am binding is: http://developer.xtify.com/display/sdk/Getting+Started+with+Apple+Push+Notification+Service, fwiw. I updated the reference to getXtifyOptions as you recommended, but I have the same result. I got as far as I have with the github library you referenced, but I will keep digging.

我正在处理的绑定可在以下位置获得:https://github.com/lordscarlet/monotouch-bindings/tree/master/Xtify

The binding I am working on is available at: https://github.com/lordscarlet/monotouch-bindings/tree/master/Xtify

推荐答案

首先,这个 API 的设计很糟糕,它依赖 #define 预处理器指令来进行初始配置,例如 ApiKey、标题上的大量空格……只是为了提几个问题.

First of all this API has a horrible design, it relies on #define preprocessor directives for initial configurations like ApiKey, tons of spaces on headers... just to mention a few issues.

您可以在此处找到绑定项目,请对其进行测试并告诉我它是否能解决您的问题.

You can find a Binding Project here, please test it and tell me if it solves your issues.

https://dl.dropbox.com/u/2058130/random%20stuff/XtifyLib.zip

尚未在您的绑定上设置 APIKey.

APIKey has not been set on your bindings.

在 SDK 头文件中,您会发现 XLXtifyOptions.hXLXtifyOptions.m 这意味着 XLXtifyOptions 类不在静态中XtifyPush 所以我拿了两个文件,稍微修改了它们,然后创建了另一个名为 libXtifyLibHelper.a 的静态胖(ARMv7、ARMv7s 和 i386)库.

Inside the SDK headers files, you will find XLXtifyOptions.h and XLXtifyOptions.m this means XLXtifyOptions class does not live inside the Static XtifyPush so I took both files, modified them a little bit and created another static fat (ARMv7, ARMv7s and i386) library called libXtifyLibHelper.a.

该库包含两个辅助对象消息 getXtifyOptionsWithAppKey:locationRequired:backgroundLocationRequired:logging:multipleMarkets:manageBadge:getXtifyOptionsWithAppKey:,它们将帮助您正确设置 API 密钥.

This library contains two helper objc messages getXtifyOptionsWithAppKey:locationRequired:backgroundLocationRequired:logging:multipleMarkets:manageBadge: and getXtifyOptionsWithAppKey: which will help you to correctly set the API key.

请使用上述帮助程序之一来设置您的 API Key,这些已在 XLXtifyOptions 类中绑定为静态方法.

Please use one of the above helpers to set you API Key, those has been bound as static methods inside XLXtifyOptions class.

作为旁注,您不必担心 libXtifyLibHelper.a 它将在您构建提供的项目时自动 (TM) 包含在您的 DLL 中.

As a side note you don't have to worry for libXtifyLibHelper.a it will be automagically (TM) be included inside your DLL when you build the provided project.

希望能帮到你

亚历克斯

这篇关于MonoTouch 绑定到 ObjectiveC 库不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆