Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch binding to ObjectiveC library not working

the .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

the .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

Global.h:

#define xAppKey @"abc123"

#define xLocationRequired NO

#define xRunAlsoInBackground FALSE    

#define xBadgeManagerMethod XLInboxManagedMethod 

#define xLogging TRUE

#define xMultipleMarkets FALSE

My binding definition:

[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,, );
    //      
}

These return null:

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

The vendors instructions for getting started:

  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.

This is related to: Binding #define used as constant

MORE INFORMATION:

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'. 

EDIT

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.

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

like image 710
Doug Moore Avatar asked Dec 20 '22 08:12

Doug Moore


1 Answers

The correct binding for getVendorOptions should looks like this:

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

the get part and the Capitalization is done by convention. Look at the code generated for this. GetAppKey is fine as long as you bind it as a method and not a property. Note that it shouldn't return null but throw an exception.

About

MyNamespace.Current;

I don't see any definition for it. So I don't know what's wrong.

At this point, I've some concerns on how your building your native library and including it inside of your managed one (re: the exception on the device). Make sure you're doing it right, look at tons of examples in https://github.com/mono/monotouch-bindings

like image 130
Stephane Delcroix Avatar answered May 10 '23 23:05

Stephane Delcroix