0

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

greatwolf
  • 20,287
  • 13
  • 71
  • 105
lodestar
  • 64
  • 1
  • 12
  • I have a faint memory pushes wont work while the app is open. As a work around cant you make calls to some server when the app is running? – Amir Apr 10 '16 at 11:02
  • Thank you for your consideration. When app is running and received notification, app should save notification to local database, so user can show lastest notification later. I should implement this functionality. My app could not receive notification when it is running. But it receive notification when it is not running. So I should fix this issues. Let's discuss about this issues please. Thanks. – lodestar Apr 10 '16 at 12:25
  • As work around, you can save data to a server and make your app make calls every few seconds to the server if it is open. – Amir Apr 10 '16 at 13:38
  • http://stackoverflow.com/questions/14872088/get-push-notification-while-app-in-foreground-ios – Amir Apr 10 '16 at 13:47
  • Thank you for your help. But also I should display notification on running app when app get notification from pushwoosh server. And I developed my app with corona sdk. Thanks again. (Y) – lodestar Apr 10 '16 at 14:44
  • The notification will be delivered to your app when in the foreground, it is then up to you to display that however you want, as your app is in the foreground why would you want to display it as a notification anyway? But if you must, then use a local notification. – Gruntcakes Apr 10 '16 at 18:01
  • As I mentioned I should save notifications on my local database. So user can see latest notifications in future. But my app can not receive APN in foreground. Also iphone os do not display any APN in foreground. However, iphone os display APNs in background well. I can not understand it. It is my issue. How can I receive APN on running app. It is implemented with corona. Thanks. – lodestar Apr 10 '16 at 19:16
  • Have you implemented application:didReceiveRemoteNotification:fetchCompletionHandler: ? – Gruntcakes Apr 10 '16 at 21:17

0 Answers0