0

我已经正确实现了bump的api,并添加了以下代码:

- (void) configureBump {

[BumpClient configureWithAPIKey:@"your api key" andUserID:[[UIDevice currentDevice] name]];

[[BumpClient sharedClient] setMatchBlock:^(BumpChannelID channel) { 
/* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Matched with user" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
 [alert show];
 [alert release];*/
NSLog(@"Matched with user: %@", [[BumpClient sharedClient] userIDForChannel:channel]); 
[[BumpClient sharedClient] confirmMatch:YES onChannel:channel];
 }];

[[BumpClient sharedClient] setChannelConfirmedBlock:^(BumpChannelID channel) {
/*  UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Channel with" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
 [alert show];
 [alert release];*/
NSLog(@"Channel with %@ confirmed.", [[BumpClient sharedClient] userIDForChannel:channel]);


    [[BumpClient sharedClient] sendData:[[NSString stringWithFormat:@"hi"] dataUsingEncoding:NSUTF8StringEncoding]
                              toChannel:channel];

}];

[[BumpClient sharedClient] setDataReceivedBlock:^(BumpChannelID channel, NSData *data) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Data received" message:[NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
[alert show];
[alert release];
NSLog(@"Data received from %@: %@", 
      [[BumpClient sharedClient] userIDForChannel:channel], 
      [NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding]);
NSString  *receivedBumpData=[NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding];
if(receivedBumpData.length!=0){
    CardAvailableLandscape *cardObject=[[CardAvailableLandscape alloc] init];
    [cardObject bumpInsertFunction:receivedBumpData];
}
}];

[[BumpClient sharedClient] setConnectionStateChangedBlock:^(BOOL connected) {
if (connected) {
    /* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"bump Coneected"   message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
     [alert show];
     [alert release];*/
    NSLog(@"Bump connected...");
} else {
    /* UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Bump disconnected..." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
     [alert show];
     [alert release];*/
    NSLog(@"Bump disconnected...");
}
}];

[[BumpClient sharedClient] setBumpEventBlock:^(bump_event event) {
switch(event) {
    case BUMP_EVENT_BUMP:{
        /*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Bump detected." message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
         [alert show];
         [alert release];*/
        NSLog(@"Bump detected.");

        break;
    }
    case BUMP_EVENT_NO_MATCH:
    {
        /*UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"No match." message:nil   delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil ];
         [alert show];
         [alert release];*/
        NSLog(@"No match.");

        break;
    }
}
}];
}

此代码取自示例项目。建立连接。但我似乎无法发送文件:我尝试了本教程:

http://appgenor.blogspot.it/2010/02/using-bumps-new-api-to-exchange-data.html

但是无法创建 Bumb 对象。它给了我一个错误。凹凸尚未实施。所以它不在sdk中,我想......

bumpObject = [[Bump alloc] init];   // Bump *bumpObject;

请帮忙!!

4

1 回答 1

0

我查看了您提到的链接,它似乎有点旧。您使用静态函数创建凹凸对象:[BumpClient sharedClient],它也为您调用连接。我也在尝试使用它,但是在检测到碰撞时遇到问题,但我可以发送数据。我正在使用 iPod 和 bu.mp 网站来测试代码。

于 2012-06-11T08:58:13.247 回答