Skip to content

Integrate with React Native

Currently GetSocial SDK does not have a plugin for Apache Cordova, it is planned for the near future.
Until then we created a small guide how can you create your own plugin to be able to use GetSocial SDK from your app.

Plugin setup

To create GetSocial plugin, you will need to use plugman tool.

1
npm install -g plugman

Now you can create the plugin:

1
plugman create --name GetSocialCoreBridge --plugin_id im.getsocial.cordova.plugin.core --plugin_version 1.0

After GetSocialCoreBridge plugin is created, you need to add the platforms you want to support. Our sample supports iOS
and Android, so we’re adding both.

1
2
3
cd GetSocialCoreBridge
plugman platform add --platform_name ios
plugman platform add --platform_name android

Now the plugin stub is ready, we can add it to our project. Login to your app’s folder to do this.

1
cordova plugin add ../GetSocialCoreBridge --link // --link parameter links the plugin's original source the project

Android

  1. Add GetSocial frameworks as dependency to android/app/build.gradle file:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    buildscript {
        ...
        repositories {
            ...
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
        ...
    }
    
    dependencies {
        ...
        classpath "gradle.plugin.im.getsocial:plugin:[0,1)"
    }
    
  2. Add plugin to android/app/build.gradle file:

    1
    2
    ...
    apply plugin: 'im.getsocial'
    

  3. Get your GetSocial App Id from the “App settings” section on the GetSocial Dashboard:

    GetSocial App Id

  4. In the same file, set GetSocial Application ID:

    1
    2
    3
    4
    5
    6
    android {
        ...
        getsocial {
            appId "<YOUR_APP_ID>"
        }
    }
    

Please note this is the basic integration of GetSocial SDK, for complete guide check out the manual integration guide.

iOS

  1. Download the latest GetSocial frameworks from the Downloads page.
  2. In Xcode, in the project navigator, right click FrameworksAdd Files to [your project’s name] and add GetSocial.framework
  3. Select General and add GetSocial.framework to Embedded Binaries section.
  4. Get your GetSocial App Id from the “App settings” section on the GetSocial Dashboard:

    GetSocial App Id
    1. Edit Info.plist file and add your GetSocial Application ID:

    1
    2
    3
    4
    <plist>
    ...
    <key>im.getsocial.sdk.AppId</key>
    <string><YOUR_APP_ID></string>
    

Please note this is the basic integration of GetSocial SDK, for complete guide check out the manual integration guide.

Implementation examples

We added 3 sample methods with their native implementations as an example.

  1. Check if SDK is initialized:
    1
    console.log("SDK Initialized: " + GetSocialCoreBridge.isInitialized());
    
  2. Register a callback to be notificed when SDK gets initialized:
    1
    2
    3
    GetSocialCoreBridge.onInitialized(function(){
        console.log("GetSocial SDK is initialized.");
    });
    
  3. Send an invite:
    1
    2
    3
    4
    5
    GetSocialCoreBridge.sendInvite("email", function(success){
        console.log("invite sent");
    }, function(error) {
        console.log("error while sending an invite: " + error.domain);
    });
    

Android Bridge Code

Add your bridge method’s to GetSocialCoreBridge.java class, which extends CordovaPlugin, and override execute method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
    if (action.equalsIgnoreCase("isInitialized")) {
        isInitialized(callbackContext);
        return true;
    }
    if (action.equalsIgnoreCase("onInitialized")) {
        onInitialized(callbackContext);
        return true;
    }
    if (action.equalsIgnoreCase("sendInvite")) {
        sendInvite(args, callbackContext);
        return true;
    }
    return false;
}

Example implementation of GetSocial.whenInitialized call:

1
2
3
4
5
6
private void onInitialized(final CallbackContext callbackContext) {
    GetSocial.whenInitialized(() -> {
            PluginResult result = new PluginResult(PluginResult.Status.OK);
            callbackContext.sendPluginResult(result);
    });
}

Example implementation of GetSocial.isInitialized() call:

1
2
3
4
private void isInitialized(final CallbackContext callbackContext) {
    PluginResult result = new PluginResult(PluginResult.Status.OK, GetSocial.isInitialized());
    callbackContext.sendPluginResult(result);
}

Example implementation of GetSocial.sendInvite(...) call:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private void sendInvite(final CordovaArgs args, final CallbackContext callbackContext) {
    try {
        String inviteChannel = args.getString(0);
        GetSocial.sendInvite(inviteChannel, new InviteCallback() {
            @Override
            public void onComplete() {
                PluginResult result = new PluginResult(PluginResult.Status.OK);
                callbackContext.sendPluginResult(result);
            }

            @Override
            public void onCancel() {
                PluginResult result = new PluginResult(PluginResult.Status.ERROR, "canceled");
                callbackContext.sendPluginResult(result);
            }

            @Override
            public void onError(Throwable throwable) {
                PluginResult result = new PluginResult(PluginResult.Status.ERROR, throwable.getMessage());
                callbackContext.sendPluginResult(result);
            }
        });
    } catch (Exception e) {
        System.out.println("ERROR: " + e.getLocalizedMessage());
    }
}

iOS Bridge Code

Add your bridge method’s to GetSocialCoreBridge.h class, which extends CDVPlugin.

Example implementation of [GetSocial executeWhenInitialized] call:

1
2
3
4
5
6
- (void) whenInitialized:(CDVInvokedUrlCommand*)command {
    [GetSocial executeWhenInitialized:^{
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    }];
}

Example implementation of [GetSocial isInitialized] call:

1
2
3
4
5
- (void) isInitialized:(CDVInvokedUrlCommand*)command {
    BOOL isInitialized = [GetSocial isInitialized];
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:isInitialized];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

Example implementation of [GetSocial sendInvite...] call:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
- (void) sendInvite:(CDVInvokedUrlCommand*)command {
    NSString* inviteChannel = [command.arguments objectAtIndex:0];
    [GetSocial sendInviteWithChannelId:inviteChannel success:^{
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

    } cancel:^{
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"cancel"];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    } failure:^(NSError * _Nonnull error) {
        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.debugDescription];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

    }];
}

Still have questions?

If you still have a questions how to integrate GetSocial SDK in to a React Native application, send a message to our support team.

Give us your feedback! Was this article helpful?

😀 🙁