excellent developers:
I have developed corona sdk
project to implement push notification for android and iPhone.
In my corona sdk
project, I used GCM
server for android version, and pushwoosh server
for iPhone version.
Android version works well now. But iPhone version can receive push notification on only not running application. iPhone version can not receive push notification from pushwoosh
on running application.
I am searching solution of this issue for over 2 days, but I can not find any solutions in corona sdk
project.
I shared registering/receiving push notification code from main.lua.
-------------------- main.lua --------------------
if ( system.getInfo("platformName") == "iPhone OS" ) then
notifications.registerForPushNotifications()
end
local function notificationListener( event )
if ( event.type == "remoteRegistration" ) then
local deviceToken = myData.tokenID
local deviceType = 1 --default to iOS
if ( system.getInfo("platformName") == "Android" ) then
deviceType = 3
end
if(deviceType == 1) then
local PW_APPLICATION = "XXXXX-XXXXX" --use your app ID in PushWoosh
local PW_URL = "https://cp.pushwoosh.com/json/1.3/registerDevice"
local function networkListener( event )
if ( event.isError ) then
--error occurred
native.showAlert( "Notification Registration Failed", "An Error Contacting the Server has Occurred.", { "OK" } )
else
--registration successful!
print( "-----------------------------PushWoosh registration successful", system.getInfo("deviceID") )
end
end
local commands_json =
{
["request"] = {
["application"] = PW_APPLICATION,
["push_token"] = deviceToken,
["language"] = "en", --OR: system.getPreference( "ui", "language" ),
["hwid"] = system.getInfo("deviceID"),
["timezone"] = 3600, --offset in seconds
["device_type"] = deviceType
}
}
local post_body = json.encode( commands_json )
local headers = {}
headers["Content-Type"] = "application/json"
headers["Accept-Language"] = "en-US"
local params = {}
params.headers = headers
params.body = post_body
network.request ( PW_URL, "POST", networkListener, params )
end
elseif ( event.type == "remote" ) then
if ( system.getInfo("platformName") == "Android" ) then
native.showAlert(event.alert.."on android")
else
native.showAlert(event.alert.."on iphone")
end
print("////////////////////////////////////// I got push notification("..event.alert.."). ////////////////////////////")
end
end
local launchArgs = ...
if ( launchArgs and launchArgs.notification ) then
notificationListener( launchArgs.notification )
end
Runtime:addEventListener( "notification", notificationListener )
Look forward to hearing good solutions to receive push notifications on running application in iPhone.
How can I implement corona sdk
code or project settings?
Regards. Lion