14 August 2017
Introducing new Facebook “v4a” plugin
Similar to the recent updates we made to the Google IAP plugin to help combat “App Not Responding” (ANR) reports in the Google Play console, we have released an updated Facebook v4a plugin to reduce the incidence of ANR errors. Here’s what you need to know…
Why a new updated plugin?
The last revision of the Facebook plugin begins initialization when you first
require() it, and it does not return to the calling module until initialization is complete. On Android devices, this may appear (to Google) that the application isn’t responding, thus generating an ANR report.
To solve this, we have made the new Facebook v4a plugin asynchronous. The new process involves starting the initialization when you require the plugin, plus a new facebook.init() API to register a listener to be called when the initialization process completes.
Using the new plugin
To use the new plugin version, you need to do four things:
- Change your
build.settingscode to use the new plugin. Simply change
- Change any Lua file that requires the plugin to use the new plugin. Simply change
- Make sure you’re using Corona version
2017.3068or later (
2017.3068is the most recent public release at the time of this writing).
- Following the first time you
require()the plugin, likely within
main.lua, add a call to facebook.init().
New initialization API
Since the new Facebook v4a plugin is asynchronous, you need to know when initialization is actually complete. Calling the new facebook.init() API gives you a chance to define a specific function which will be called when initialization completes. Once that function receives the
"fbinit" event, you can safely call other Facebook API calls like facebook.publishInstall() or facebook.login() (although you should probably defer asking the player to log in until a point in your game which makes sense).
The listener function referenced in facebook.init() will also be used for other Facebook API calls to handle
"fbconnect" events. Because of this, you only need to call facebook.setFBConnectListener() if you wish to use a different function to process your
"fbconnect" events. See the integration documentation for more information and examples.
While this update only truly affects Android builds, you should follow similar behavior for iOS builds to maximize cross-platform compatibility. ANRs can be a silent error that you may never know about, so we strongly encourage you to update to the Facebook v4a plugin, especially if you have an active Android user base.