Social Message Plugin for Cordova 3.0

The old Social Message plugin

Almost a year ago, I wrote an open source plugin for PhoneGap / Cordova. The plugin allowed PhoneGap developers to easily post messages from their app to services like Facebook and Twitter utilising the native share features.

The plugin bridged functionality between PhoneGap / Cordova’s UIWebView and the native iOS application. It was composed of a single JavaScript interface and a native objective-c implementation but didn’t follow any strict standards.

New plugin architecture

If you’re a developer for PhoneGap / Cordova, you’ve probably noticed that with the version 3.0 CLI installing plugins is really easy. The only drawback is that older plugins will need to be updated to work.

I’m pleased to announce, my Social Message plugin has been rewritten to support the “add plugin” command.

Usage

1 step install

1
$ cordova plugin add https://github.com/leecrossley/cordova-plugin-social-message.git

Way-hey! That’s it, you are done my good friend. You do not need to reference any JavaScript, the Cordova plugin architecture will add a socialmessage object to your root automatically when you build. Good times.

In your JavaScript

After your deviceready event has been fired, you can simply pass a message object with a “text” property to the send function:

1
2
3
4
var message = {
text: "This is a test message"
};
window.socialmessage.send(message);

The above code will allow the message to be shared with all built in activity types. If you want to specify activity types to include, add an “activityTypes” array to your message object:

1
2
3
4
5
var message = {
text: "This is a test message",
activityTypes: ["PostToFacebook", "PostToTwitter"]
};
window.socialmessage.send(message);

This example will allow the user to only post the message to Facebook or Twitter.

A complete list of activity types can be found here. You should omit the “UIActivityType” prefix when adding to your array.

Platform support

The plugin is currently only implemented for iOS but I’m working on Android and Windows Phone 8 support, based on my old plugin and using the new standard.

Just a thought…

Wouldn’t it be great if there was some kind of plugin registry like node package manager… cough