Developers Quick start

Easy as 1-2-3

We've worked very hard into making the integration of the Bridgefy SDK with your app as easy as pie. With just a handful of easy-to-remember callbacks, configuration options, and an efficient memory footprint, you'll be ready to start in no time.


SDK Quick Start

1.- Instance and start!

Android

@Override
public void onRegistrationSuccessful(BridgefyClient bridgefyClient) {
    // Once the API_KEY has been checked, Bridgefy is ready to start operations
    Bridgefy.start(deviceListener, messageListener);
}


iOS

//Objective-C
BFTransmitter * transmitter = [[BFTransmitter alloc] initWithApiKey:@"YOUR API KEY"];
//BFTransmitterDelegate protocol must be implemented.
transmitter.delegate = self;

[transmitter start];


2.- Nearby peer detection

Android
@Override
public void onDeviceConnected(Device device) {
    // Prepare a Message object for the new found device
    HashMap message = new HashMap();
    message.put("key", "Hello world!");

    // Send a message to the found device
    device.sendMessage(message);
}
iOS

- (void)transmitter:(BFTransmitter *)transmitter didDetectConnectionWithUser:(NSString *)user {
    // Your code here
}




3.- Send data

Android


{
    // Prepare a Message object for the new found device
    HashMap message = new HashMap();
    message.put("key", "Hello world!");

    // Send a message to the found device
    device.sendMessage(message);
}            



iOS
//Objective-C
// Initialize with a serializable NSDictionary object.
NSDictionary *payload = @{@"text" : @"Hello world!"};
// Identifier received previously in the connection detection.
// This one is just an example.
NSString * receiverUser = @"6655a16c-8209-46c4-9c51-21d8df3efb95";
NSError * error = nil;
NSString * packetID = [transmitter sendDictionary:payload
    withData:nil
    toUser:receiverUser
    options: (BFSendingOptionNoEncrypted |
    BFSendingOptionDirectTransmission)
    error: &error];    

4.- Receive data

Android


@Override
public void onMessageReceived(Message message) {
    // Do something with the received message
    String s = (String) message.getContent().get("key");
}            




iOS

- (void)transmitter:(BFTransmitter *)transmitter
        didReceiveDictionary:(NSDictionary * _Nullable) dictionary
                    withData:(NSData * _Nullable)data
                    fromUser:(NSString *)user
                    packetID:(NSString *)packetID
                   broadcast:(BOOL)broadcast
                        mesh:(BOOL)mesh {
                        // Your code here
}