2012-06-08 37 views
0

我試圖與kiip庫做到這一點:MonoTouch Objective C綁定,正確的軌道?

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


} 

回答

2

您的綁定有幾個問題。

構造函數必須聲明爲「IntPtr的構造」,所以更改「空缺InitWithKey」是:

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

的第二個問題是,您使用的是出口「initWithKey:」只有一個參數(我們知道這是因爲有一個冒號的單個實例),因此您可能需要找出構造函數的實際名稱,或使用單個參數(鍵),就像我在示例中所做的那樣。

您對「DidStartSession」的綁定是錯誤的。看看簽名是「經理: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) 

請注意,「info」字樣,參數的名稱永遠不會是選擇器名稱的一部分。

getActivePromos的綁定也看起來錯了,我懷疑它應該返回一個值,但是你聲明它返回void。

也可能有其他問題。