Hi guys, I’m going mad about push notifications in my app. I followed every tutorial I’ve found (included the pushwoosh official) but nothing happens, at the first start no popup for push notification comes out. I created my app project in google dev, enabled google cloud posting and copied the server key into pushwoosh. Then first configured config.lua as follows:
--calculate the aspect ratio of the device: local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 320 or math.ceil( 480 / aspectRatio ), height = aspectRatio \< 1.5 and 480 or math.ceil( 320 \* aspectRatio ), scale = "letterBox", fps = 30, graphicsCompatibility = 1, }, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, notification = { google = { projectNumber = "214414349737" }, } }
build.settings configuration
android = { usesPermissions = { -- Required by the MapView to fetch its contents from the Google Maps servers. "android.permission.INTERNET", -- Optional permission used to display current location via the GPS. "android.permission.ACCESS\_FINE\_LOCATION", "android.permission.ACCESS\_NETWORK\_STATE", "android.permission.WRITE\_EXTERNAL\_STORAGE", "com.google.android.providers.gsf.permission.READ\_GSERVICES", "android.permission.ACCESS\_FINE\_LOCATION", -- Optional permission used to display current location via WiFi or cellular service. "android.permission.ACCESS\_COARSE\_LOCATION", --Chiamate "android.permission.READ\_PHONE\_STATE", --Chiamate2 "android.permission.CALL\_PHONE", --Fotocamera "android.permission.CAMERA", "android.permission.WRITE\_EXTERNAL\_STORAGE", --Notifiche PUSH "android.permission.GET\_ACCOUNTS", "android.permission.RECEIVE\_BOOT\_COMPLETED", "com.google.android.c2dm.permission.RECEIVE", ".permission.C2D\_MESSAGE", },
and then the main.lua
local launchArgs = ... local json = require "json" if launchArgs and launchArgs.notification then native.showAlert( "launchArgs", json.encode( launchArgs.notification ), { "OK" } ) end -- notification listener local function notificationListener( event ) if ( event.type == "remote" ) then --handle the push notification elseif ( event.type == "remoteRegistration" ) then --code to register your device with the service end end Runtime:addEventListener( "notification", notificationListener ) local function notificationListener( event ) if ( event.type == "remote" or event.type == "local" ) then --handle the push or local notification elseif ( event.type == "remoteRegistration" ) then local deviceToken = event.token local deviceType = 1 --default to iOS if ( system.getInfo("platformName") == "Android" ) then deviceType = 3 end print( "Setting up with PushWoosh" ) local DeviceID = event.token local PW\_APPLICATION = "93E79-7FD0E" --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, ["device\_id"] = DeviceID, ["language"] = "en", --OR: system.getPreference( "ui", "language" ), ["hw\_id"] = 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 end Runtime:addEventListener( "notification", notificationListener )
I’m going REALLY mad, I don’t understand what’s wrong… Any help is really appreciated. Thanks in advance