I have seen these features mentioned in the patch notes several times, but cannot find any documentation for them. Can they be used at the moment or are they upcoming features?
Yes, they can definitely be used but it’s going to be hard since there’s no documentation out yet.
This is on the list of things to fix.
While waiting for documentation for push, here’s some example code for the client to get you going:
local function push_listener(self, payload, origin)
if origin == push.ORIGIN_LOCAL then
-- This was a local push
...
end
if origin == push.ORIGIN_REMOTE then
-- This was a remote push
...
end
end
function init(self)
local alerts = {push.NOTIFICATION_BADGE, push.NOTIFICATION_SOUND, push.NOTIFICATION_ALERT}
-- Android ignores "alerts" parameter
push.register(alerts, function (self, token, error)
if token then
-- NOTE: %02x to pad byte with leading zero on iOS. Android token can be used as is.
local token_string = ""
for i = 1,#token do
token_string = token_string .. string.format("%02x", string.byte(token, i))
end
print(token_string) -- The device token to use when sending
push.set_listener(push_listener)
else
-- Push registration failed.
print(error.error)
end
end
end
Local push:
-- Schedule a local push in 3 seconds
local payload = '{ "data" : { "field" : "Some value", "field2" : "Other value" } }'
id, err = push.schedule(3, "Update!", "There are new stuff in the app", payload, {}) -- The last parameter can contain device specific settings. Safe to omit.
if err then
-- Something went wrong
...
end
Setting badge count on iOS:
push.set_badge_count(42)
2 Likes
The Facebook API is still quite rough around the edges. It’s used internally but we’d like to polish it before we release it into the wild. The plan for that is not too far into the future.