Difference between revisions of "NotificationManager:registerForPushNotifications"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
+
<languages />
=== Description ===
+
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
Register device for receiveng push notifications.
+
'''<translate>Class</translate>:''' [[Special:MyLanguage/NotificationManager|NotificationManager]]<br/>
 +
=== <translate>Description</translate> ===
 +
<translate>Register device for receiveng push notifications.
  
 
On Android this method accepts the string value of project ID in Google API console.
 
On Android this method accepts the string value of project ID in Google API console.
Line 14: Line 16:
 
Upon successful registration you will receive the device token with the event object, that you should pass to your server, which will be sending push notifications.
 
Upon successful registration you will receive the device token with the event object, that you should pass to your server, which will be sending push notifications.
  
Although this method can be called multiple times, and even if already registered it will still return same device token with the event object, but it is still recommended to persistant store device token if you'll be needing it later.
+
Although this method can be called multiple times, and even if already registered it will still return same device token with the event object, but it is still recommended to persistant store device token if you'll be needing it later.</translate>
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
  NotificationManager:registerForPushNotifications()
 
  NotificationManager:registerForPushNotifications()
</source>
+
</syntaxhighlight>
 +
=== <translate>Examples</translate> ===
 +
'''Registering for push notifications'''<br/>
 +
<syntaxhighlight lang="lua">--retrieve shared instance
 +
local mngr = NotificationManager.getSharedInstance()
 +
 
 +
--if registration completed succesfully
 +
mngr:addEventListener(Event.PUSH_REGISTRATION, function(e)
 +
--getting device token
 +
local token = e.deviceToken
 +
 +
--sending token to your server
 +
local loader = UrlLoader.new("http://yourdomain.com/register.php?token="..token)
 +
loader:addEventListener(Event.COMPLETE, function()
 +
--token succesfuly deliverd
 +
end)
 +
end)
 +
 
 +
--if registration failed
 +
mngr:addEventListener(Event.PUSH_REGISTRATION_ERROR, function(e)
 +
--device could not been registered now
 +
--try again later
 +
print(e.error)
 +
end)
 +
 
 +
 
 +
--try to register for push notifications
 +
mngr:registerForPushNotifications("953841987672")</syntaxhighlight>

Latest revision as of 14:32, 13 July 2023


Available since: Gideros 2011.6
Class: NotificationManager

Description

Register device for receiveng push notifications.

On Android this method accepts the string value of project ID in Google API console.

On IOS this method does not require any input, but for compatability purpose, you may pass same string as for Android or any other string, as it won't do any harm.

Before calling this method you should register for two events:

for successful registration
for registration error

Upon successful registration you will receive the device token with the event object, that you should pass to your server, which will be sending push notifications.

Although this method can be called multiple times, and even if already registered it will still return same device token with the event object, but it is still recommended to persistant store device token if you'll be needing it later.

 NotificationManager:registerForPushNotifications()

Examples

Registering for push notifications

--retrieve shared instance
local mngr = NotificationManager.getSharedInstance()

--if registration completed succesfully
mngr:addEventListener(Event.PUSH_REGISTRATION, function(e)
	--getting device token
	local token = e.deviceToken
	
	--sending token to your server
	local loader = UrlLoader.new("http://yourdomain.com/register.php?token="..token)
	loader:addEventListener(Event.COMPLETE, function()
		--token succesfuly deliverd
	end)
end)

--if registration failed
mngr:addEventListener(Event.PUSH_REGISTRATION_ERROR, function(e)
	--device could not been registered now
	--try again later
	print(e.error)
end)


--try to register for push notifications
mngr:registerForPushNotifications("953841987672")