Joseph Anderson
Joseph Anderson

Reputation: 4144

MonoTouch Objective C Binding, Right Track?

I am trying to do this with the kiip library:

http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types

I am getting an error saying my binding project cannot be found, however, I did add a reference to it in the project.

Do I use the code like this:

public override void ViewDidLoad ()
    {
        var kp = new KiipMonoTouchBinding.IKPManager();

            kp.InitWithKey("abc", "123");

    }

Am I doing this correctly?

  namespace KiipMonoTouchBinding
{
interface IKPManager
{
    //kiip code

    //KPManager* manager = [[KPManager alloc] initWithKey:@"0b56b49f621ad7f42fd85de7e461f9dd" secret:@"ac3abfdf5cb86ce0febba0c8afd2744e" testFrequency:100];
    [Export("initWithKey:")]
    void InitWithKey(string key, string secret);

//[[KPManager sharedManager] unlockAchievement:@"_achievement_id_"];
    [Export ("unlockAchievement:")]
    void UnlockAchievement(string achivementId);

//
//- (IBAction)saveLeaderboard {
//    NSLog(@"save leaderboard");
//    [[KPManager sharedManager] updateScore:100 onLeaderboard:leaderboard_id.text];
//}

//[[KPManager sharedManager] updateScore:_score_ onLeaderboard:@"_leaderboard_id_"];

    [Export("updateScore:")]
    void UpdateScore(int score, string leaderboardId);

    //- manager:(KPManager*)manager didStartSession:(NSDictionary*)response {
    [Export("didStartSession:response")]
    void DidStartSession(NSDictionary response);

    //updateLatitude:(double)37.7753 longitude:(double)-122.4189];
    [Export("updateLatitude:_latitude, longitude")]
    void UpdateLatitude(double latitude, double longitude);

    [Export("updateUserInfo:info")]
    void UpdateUserInfo(NSDictionary info);

    // [[KPManager sharedManager] getActivePromos];
    [Export("getActivePromos")]
    void GetActivePromos();




// Update the user's location
// [manager updateLatitude:_latitude_ longitude:_longitude_];

// Update the User's information
// NSDictionary* info = [[[NSDictionary alloc] initWithObjectsAndKeys:
                    //    _email_, @"email",
                   //     _alias_, @"alias",
                  //      nil]
                 //     autorelease];
//  [manager updateUserInfo:info];


}

Upvotes: 0

Views: 339

Answers (1)

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

Your binding has several problems.

Constructors must be declared as "IntPtr Constructor", so change the "void InitWithKey" to be:

 [Export ("initWithKey:")]
 IntPtr Constructor (string key);

The second problem is that the export you are using "initWithKey:" takes a single parameter (we know this because there is a single instance of the colon), so you might need to find out what the actual name of the constructor is, or use a single parameter (key), like I did in the sample.

Your binding for "DidStartSession" is wrong. Look at the signature which is "manager:didStartSession:" so it should be:

 [Export ("manager:didStartSession:")]
 void DidStartSession (KPManager manager, NSDictionary sessionREsponse);

Your UpdateLatitude is also wrong, again, the selector you added is incorrect, I can not guess what it is without looking at the code, but if this really gets two parameters (longitude and latitude), it would look like this (I am making the selector name up):

 [Export ("updateLatitude:andLongitude:")]
 void UpdateLocation (double latitude, double longitude)

UpdateUserInfo is also wrong, most likely it takes a single parameter (guessing again):

 [Export ("updateUserInfo:")]
 void UpdateUserInfo (NSDictionary info)

Notice that the "info" word, the name of the parameter is never part of the selector name.

The binding for getActivePromos also looks wrong, I suspect it should return a value, but you declared it as returning void.

There might be other problems as well.

Upvotes: 2

Related Questions