Posted on by

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:

settings =
{
   plugins =
   {
      --key is the name passed to Lua's 'require()'
      ["CoronaProvider.native.popup.social"] =
      {
      --required
      publisherId = "com.coronalabs",
      },
   },
}

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.

local options = {
   service = "twitter",
   message = "Check out these photos!",
   listener = socialEventListener,
   image = {
      { filename = "pic.jpg", baseDir = system.ResourceDirectory },
      { filename = "pic2.jpg", baseDir = system.ResourceDirectory }
   },
   url = "http://coronalabs.com"
}

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:

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:

local isFacebookAvailable = native.canShowPopup( "social", "facebook" )
local isTwitterAvailable = native.canShowPopup( "social", "twitter" )
local isSinaWeiboAvailable = native.canShowPopup( "social", "sinaWeibo" )

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.


Posted by . Thanks for reading...

19 Responses to “Tutorial: Introducing the “Social” Plugin (iOS)”

  1. Rob Miracle

    Yes and No. No, it does not replace facebook.login() if your app needs to call facebook.request() or facebook.dialog() to exchange data with their OpenGraph API.

    But if all you want to do is have the app user post something to their timeline, then you don’t need the complexity of building your own tool in Facebook to do that.

    Reply
  2. ed69

    Great feature, thank you Rob!

    If I’d like to use with current Corona SDK build – should I limit iOS version with MinimumOSVersion=”6.0″ in build.settings?

    Thanks!

    Reply
    • Rob Miracle

      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.

      Reply
  3. Haakon

    Seems to not be working for iOS 7 – even though the twitter account is set up and logged in in system settings, all I get is “there are no twitter accounts configured”.

    Reply
    • Danny

      Hey Haakon.

      We tested this against iOS7 during development and after and it worked as expected.

      Could you please outline your testing steps to give us more context? Thanks

      Reply
  4. Greg

    Hi Rob – can I ask:

    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?

    Reply
  5. Kerem

    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

    Reply
  6. Grant Slender

    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.

    Reply
    • Rob Miracle

      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.

      Reply
  7. Leonardo Amora

    Hey Hello Rob!
    there is a chance of this plugin works on public version?

    there is another way to do this without the daily build?

    In my project I need only this. I think this a great feature.
    I think that would be a great idea if the plugin could be add in the plublic version with a low cost. Like pieces. :) Is just an idea. :)

    Reply
  8. Joe

    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,

    native.canShowPopup() returns FALSE

    however, the user still can use the feature.

    Do I miss anything here?

    Reply
    • Rob Miracle

      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.

      Reply
  9. Rohan Kadolkar

    Hi Rob,
    Can I detect installed social networking apps and list them in my game.
    So, that the user can pick any of them and post.

    ~Regards
    Rohan K

    Reply
    • Rob Miracle

      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.

      Rob

      Reply

Leave a Reply

  • (Will Not Be Published)