Search code examples
xcodeobjective-c-blocksbump

send file using bump


I have implemented correctly bump's api, and added this code:

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

this code has been taken from the example project. the connection is established. but i can't seem to be able to send a file: I tried this tutorial:

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

but the Bumb object can not be created. it gives me an error. the bump has not been implemented. so it is not in the sdk, i think...

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

help please!!


Solution

  • I looked at the link you mention and it seems a bit old. You create bump object using static function: [BumpClient sharedClient], which also calls connect for you. I am trying to play with it as well but having problems where bump is detected but I can send data. I am using an iPod and bu.mp website to test the code.