iphone-在使用电晕开发的运行应用程序时不会收到推送通知(服务器:pushwoosh)

时间:2016-04-10 05:17:16

标签: iphone lua push-notification corona pushwoosh

优秀的开发人员:

我开发了corona sdk项目来实现Android和iPhone的推送通知。

在我的corona sdk项目中,我使用了GCM服务器用于Android版本,而pushwoosh server用于iPhone版本。

Android版现在运作良好。但iPhone版本只能在不运行的应用程序上接收推送通知。在运行的应用程序中,iPhone版本无法从pushwoosh接收推送通知。

我正在搜索此问题的解决方案超过2天,但我在corona sdk项目中找不到任何解决方案。

我从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 )

期待听到好的解决方案,以便在iPhone上运行应用程序接收推送通知。

如何实施corona sdk代码或项目设置?

的问候。 狮子

0 个答案:

没有答案