使用bump发送文件

时间:2012-06-05 17:01:29

标签: xcode objective-c-blocks 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;
请帮忙!!

1 个答案:

答案 0 :(得分:0)

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