我正在尝试使用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];
}发布于 2012-06-10 01:38:58
您的绑定有几个问题。
构造函数必须声明为"IntPtr构造函数“,因此将”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)请注意,"info“这个词,参数的名称永远不是选择器名称的一部分。
getActivePromos的绑定看起来也是错误的,我怀疑它应该返回值,但您将其声明为返回空。
可能还有其他问题。
https://stackoverflow.com/questions/10955958
复制相似问题