Integrate with Apache Cordova¶
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.
npm install -g plugman
Now you can create the plugin:
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.
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.
cordova plugin add ../GetSocialCoreBridge --link // --link parameter links the plugin's original source the project
Android¶
- Add
GetSocial
frameworks as dependency toandroid/app/build.gradle
file:
buildscript { ... repositories { ... maven { url "https://plugins.gradle.org/m2/" } } ... } dependencies { ... classpath "gradle.plugin.im.getsocial:plugin:[0,1)" }
-
Add plugin to
android/app/build.gradle
file:
... apply plugin: 'im.getsocial'
-
Get your GetSocial App Id from the “App settings” section on the GetSocial Dashboard:
-
In the same file, set GetSocial Application ID:
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¶
- Download the latest GetSocial frameworks from the Downloads page.
- In Xcode, in the project navigator, right click Frameworks → Add Files to [your project’s name] and add
GetSocial.framework
- Select General and add
GetSocial.framework
to Embedded Binaries section. -
Get your GetSocial App Id from the “App settings” section on the GetSocial Dashboard:
1. EditInfo.plist
file and add your GetSocial Application ID:
<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.
- Check if SDK is initialized:
console.log("SDK Initialized: " + GetSocialCoreBridge.isInitialized());
- Register a callback to be notificed when SDK gets initialized:
GetSocialCoreBridge.onInitialized(function(){ console.log("GetSocial SDK is initialized."); });
- Send an invite:
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:
@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:
private void onInitialized(final CallbackContext callbackContext) {
GetSocial.whenInitialized(() -> {
PluginResult result = new PluginResult(PluginResult.Status.OK);
callbackContext.sendPluginResult(result);
});
}
Example implementation of GetSocial.isInitialized()
call:
private void isInitialized(final CallbackContext callbackContext) {
PluginResult result = new PluginResult(PluginResult.Status.OK, GetSocial.isInitialized());
callbackContext.sendPluginResult(result);
}
Example implementation of GetSocial.sendInvite(...)
call:
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:
- (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:
- (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:
- (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 an Apache Cordova application, send a message to our support team.