social-iosBack in the days of iOS 5, Apple integrated Twitter directly into the operating system. Suddenly you could tweet things that you wanted to share from the sharing screen. Shortly thereafter, Corona added the ability to use this integrated Twitter feature via our native.showPopup() API call, the same API that you can use to send an email, send an SMS message, rate apps, and link to other apps in the App Store.

Fast forward to iOS 6, where Apple created a new class which handles not only Twitter, but also Facebook and even the widely-used Chinese social networking service, Sina Weibo.

Now that Corona’s plugin system is in place, we’ve rolled out a new plugin for Pro subscribers to use. This is the Social plugin, and like the other features mentioned in this article, it works via native.showPopup().

Before You Begin…

Before you consider implementing the new Social plugin into your apps, there are a few important things to know:

  1. It is only available to Pro subscribers using recent Daily Builds.
  2. At least iOS 6 is required for full support (Twitter, Facebook, Sina Weibo).
  3. Android support is still underway.

Getting Started

Like all Corona plugins, you must bundle the Social plugin into your project by adding its details to the build.settings file. This is done as follows:

Basic Code

If you currently use the native.showPopup() feature for Twitter, implementing the new Social plugin will seem familiar. You still need an options table which contains the various parameters you’re going to send to the service. The key difference with the Social plugin is that you must add a new parameter to the table called service — this defines which of the three services you want to use.

Let’s go through these options in more detail:

  • service — a string representing which of the three services you want to use: “facebook”, “twitter”, or “sinaWeibo”.
  • message — the text of the Facebook status post, tweet, or Sina Weibo post.
  • listener — a function that will handle the return status from the call (see the documentation).
  • image — an table containing sub-tables, each of which defines an image you want to upload; each of these should contain the filename and baseDir of the image to upload.
  • url — either a single string or a table array of strings defining the URLs to include in the post.

Then, to display the Social popup within your app, simply call:

If you want to use Facebook, simply change the service option to “facebook” instead of “twitter”. Simple!

OS Considerations

Because the Social plugin requires iOS 6 or later, you might want to ensure that the app functions on iOS 5 as well. Currently, it’s estimated that only 5% of iOS users have iOS 5, and this number may drop further when iOS 7 is released. However, it may be worth taking a few extra steps as a precaution when using social features.

This matrix indicates which service is available for which OS:

Service iOS 5 iOS 6 +
Twitter native.showPopup(“twitter”) native.showPopup(“social”)
Facebook native.showPopup(“social”)
Sina Weibo native.showPopup(“social”)

Conveniently, you can use the native.canShowPopup() API to determine if a given popup is available on your device:

If any of these return false, hide or disable the button to launch the feature.

In Summary

As you can see, using the new Social plugin is simple and we’ve done everything possible to make it work with the native.showPopup() API just like you’re accustomed to.

Continue reading: 

Introducing the “Social” Plugin (iOS)