Tutorial: Introducing the “Social” Plugin (iOS)

Back 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:

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.

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:

native.showPopup( "social", options )

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:

Rob Miraclesays:

That would work, or you could check to see if it’s available with native.canShowPopup() and if it’s not, just disable the buttons on older devices or if you’re doing twitter use the native.showPopup(“twitter”) option for iOS 5.

a) could you drop in a few screen snapshots to show what the end result looks like?

b) re your comment confirming you do not need to use any of the other facebook functions (e.g. login) besides this: “if all you want to do is have the app user post something to their timeline”. Can I ask then would this plugin alone allow you to have the user able to:
– click a single button and then
– post would be auto-created for them
– post could include words you pre-populate for them (e.g. “playing game XXX and loving it”
– post could include an image (or a link to an image on a webserver)
– post could include links to app store/google play for your app

c) so if you build it how you’ve suggested as people upgrade they should automatically get the feature as their device OS is supported correct?

d) is the interface rendered from the plugin generating the UI? or does facebook send the plugin the UI definition so to speak? I assume the former?

e) I assume it includes it own login screens also then? (i.e. as you don’t need to use the facebook.login api)

f) actually typing this out now (admit I haven’t gone looking) but is there a sample app in our Corona download that gives a demo?

What I would love to see is a simple list of functionality open to mobile apps in Facebook, Twitter etc and then a check mark or X mark next to each showing whether Corona Supports it or not. Then check mark should be clickable to take us to further detail telling us more about how to make that functionality work etc. Can we have a simple document, a jump board like this? Thanks

Grant Slendersays:

With Android pushing more than 80% market penetration globally, why is Corona so iOS focused with only releasing things on that platform first? Makes me want to keep close eye on competitor SDKs which is always an uneasy way to be.

Rob Miraclesays:

Hi Grant. There are many variables and factors that determine what comes first. We don’t always build for iOS first. GPGS and Controllers are two very recent examples. GPGS supports iOS but we don’t yet.

I’m not the engineer building this, but I’m guessing that in the iOS case, it’s something cooked into the operating system and iOS has a ready-to-go SDK that was pretty easy to implement as a plugin. Android may require more work to make it happen. I’m not an Android expert, but I’ve not heard people talk about Twitter and Facebook being built into the OS like Apple did with iOS.

Rob Miraclesays:

Using native.canShowPopup() to determine if the feature should be enabled is NOT a very good idea, because from my testing, if the user doesn’t have Facebook or Twitter account setup in his/her iOS device,

Rob Miraclesays:

Hi Joe. If you have a way to allow this popup to work if they customer is not signed into Facebook and/or Twitter, you are more than welcome to not use this check to determine to show the button or not.

Rob Miraclesays:

The social plugin should let you know if the user is setup to use those social networks through the OS. But it’s possible on iOS to have the Facebook app installed, but not have iOS setup to use Facebook directly from the OS. There isn’t a good way to detect that circumstance.