I’ve been testing the v4a plugin for android and have had no luck getting the dialog callback events to fire.
This is the latest logs on Android. Dialog shows up and i can share or cancel, nothing happens after, just a applicationResume event in my system listener, but nothing in my facebook listener.
10-11 19:36:09.012 11394 11425 I Corona : ++++++++++: setPluginsLuaVariables setting isActive = true
10-11 19:36:09.153 11394 11394 I Corona : ++++++++++: FacebookController.FacebookRequestCallbackListener.onCompleted()
10-11 19:36:19.621 11394 11425 I Corona : ++++++++++: FacebookController.facebookDialog()
10-11 19:36:19.621 11394 11425 I Corona : ++++++++++: FacebookController.fetchLuaState(): com.naef.jnlua.LuaState@5c964a6
Testing on android 9, Solar2D Version 2021.3637 (2021.2.3)
My build.settings has facebookAppId and applicationChildElements, init, login, and request listeners work ok
Will try updating solar2D to latest daily build and see how it goes and post my results here. Anyone else having this problem?
EDIT:
Latest build does not solve it.
Just tested on iOS and the "dialog" == event.type is not firing as well. I do get an applicationOpen system event though with a different URL for app sharing and webview sharing
Im guessing something broke with last v4a plugin build on August.
Edit: Here is my current source code if it helps or anything
local facebook = require("plugin.facebook.v4a")
local socketUrl = require("socket.url")
local settings = require("settings")
local json = require("json")
local service = {}
------------------------- Vars
local token
local userName, userId
local onShare, onMe
local isSimulator = system.getInfo("environment") == "simulator"
------------------------- Functions
local function listener( event )
if "fbinit" == event.name then
facebook.publishInstall()
token = facebook.getCurrentAccessToken() -- Is nil when player has never connected
if token then
facebook.request("me/")
end
elseif "fbconnect" == event.name then
if "session" == event.type then -- Login
if not event.isError then
token = facebook.getCurrentAccessToken()
if token then
facebook.request("me/")
end
end
elseif "request" == event.type then
if not event.isError then
local response = json.decode(event.response)
local name = response.name
local id = response.id
if onMe then
onMe({name = name, id = id})
end
end
elseif "dialog" == event.type then
print(event.response) -- This does not work
end
end
end
local function hexToChar(hex)
return string.char(tonumber(hex, 16))
end
local function unescape(text)
return string.gsub(text, "%%(%x%x)", hexToChar)
end
local function decodeQuery(url)
local result = {}
for key, value in string.gmatch(url, "([^&=?]-)=([^&=?]+)") do
local unescaped = unescape(value)
result[key] = json.decode(unescaped)
end
return result
end
local function parseUrl(url)
local result = socketUrl.parse(url)
if result then
local decodedQuery = result.query and decodeQuery(result.query)
return result.scheme, result.path, decodedQuery
end
return false
end
local function handleNotifications(event)
if event.type == "applicationOpen" then
timer.performWithDelay(1, function()
local scheme, path, query = parseUrl(event.url)
if scheme and scheme == settings.fbScheme then
if query then
if query.method_results then -- Tested iphone x facebook app
if (query.method_results.completionGesture == "post") and query.method_results.didComplete then
if onShare then
onShare()
end
end
elseif query.bridge_args then -- Tested iphone SE 2 webview
if query.bridge_args.action_id and not query.error_code then
if onShare then
onShare()
end
end
end
end
end
end)
end
end
------------------------- Module functions
function service.setOnShare(newOnShare)
onShare = newOnShare
end
function service.setOnMe(newOnMe)
onMe = newOnMe
end
function service.init()
Runtime:addEventListener("system", handleNotifications)
facebook.init(listener)
end
function service.share(description)
description = description or "This is the description"
if isSimulator then
native.setActivityIndicator(true)
timer.performWithDelay(500, function()
native.setActivityIndicator(false)
if onShare then
onShare()
end
end)
else
if token then
local options = {
link = "https://www.zetosoft.com/landing/turbocrusher/",
description = description,
}
facebook.showDialog("link", options)
else
facebook.login()
end
end
end
return service
build.settings has everything in place. URL schemes, identifiers, plugins, permissions. As you can see, i had to add a system event listener to check applicationOpen events to fire my own callback.