【问题标题】:MonoTouch Objective C Binding, Right Track?MonoTouch Objective C 绑定,正确的轨道?
【发布时间】:2012-06-10 01:38:58
【问题描述】:

我正在尝试使用 kiip 库来做到这一点:

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

我收到一条错误消息,提示找不到我的绑定项目,但是,我确实在项目中添加了对它的引用。

我是否使用这样的代码:

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

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

    }

我这样做对吗?

  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];


}

【问题讨论】:

    标签: xamarin.ios


    【解决方案1】:

    您的绑定有几个问题。

    构造函数必须声明为“IntPtr 构造函数”,因此将“void InitWithKey”更改为:

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

    第二个问题是您使用的导出“initWithKey:”只有一个参数(我们知道这一点是因为有一个冒号实例),因此您可能需要找出构造函数的实际名称是,或者使用单个参数(键),就像我在示例中所做的那样。

    您对“DidStartSession”的绑定错误。看看签名是“manager:didStartSession:”所以它应该是:

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

    你的UpdateLatitude也是错误的,再次,你添加的选择器不正确,我不看代码我猜不出它是什么,但是如果这真的有两个参数(经度和纬度),它看起来像这样(我正在制作选择器名称):

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

    UpdateUserInfo 也是错误的,很可能它需要一个参数(再次猜测):

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

    请注意,“信息”一词,参数名称绝不是选择器名称的一部分。

    getActivePromos 的绑定看起来也有问题,我怀疑它应该返回一个值,但您将它声明为返回 void。

    可能还有其他问题。

    【讨论】:

      猜你喜欢
      • 2015-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多