register for push notification not working

I’m trying to implement push notifications in IOS with the latest daily build.

I have set up as the guide describes. Added plugin to build settings, added the relevant code. Iv also got both certificates from the developer site.

However when i build to my device, the registerfornotifications function just doesn’t seem to do anything. I dont even get any errors or warning in the console.

When in corona simulator it at least comes up with plugin not supported on this platform.

I would greatley appreciate a point in the right direction. I have used push before natively so im not a noob. Using xcode 8.4 SDK

Hi @adamjrobbo,

We’ll almost certainly need to see your code regarding this, as simplified as you can make it. Please remember to surround it with “lua” tags for clarity in the forum post.

[lua] --code [/lua]

Thanks,

Brent

Sure,

Build Settings:

[lua]

    plugins =

    {

        [“plugin.notifications”] =

        {

            publisherId = “com.coronalabs”

        },

    }, 

    notification = 

    {

        iphone =

        {

            types = { “badge”, “sound”, “alert” }

        }

    }

[/lua]

Top of main.lua

[lua]

local notifications = require( “plugin.notifications” )

notifications.registerForPushNotifications()

local launchArgs = …

if ( launchArgs and launchArgs.notification ) then

    print( launchArgs.notification.type )

    print( launchArgs.notification.name )

    print( launchArgs.notification.sound )

    print( launchArgs.notification.alert )

    print( launchArgs.notification.badge )

    print( launchArgs.notification.applicationState )

end

local json = require(“json”)

local deviceToken

local function notificationListener( event )

        print( “notification engine started!” )

      if ( event.type == “remote” and event.applicationState == “active” ) then

        --handle the push or local notification

        print( "type ", event.type ) 

        print ("event alert ", event.alert ) 

    elseif ( event.type == “remoteRegistration” ) then

        local deviceToken = event.token

        --local deviceType = 1  --default to iOS

        print( “Event Token is” … " " … event.token )

    end

end

– The notification Runtime listener should be handled from within “main.lua”

Runtime:addEventListener( “notification”, notificationListener )

[/lua]

I am planning on implementing my own push server, however i have stripped all the code from the remoteregister callback for now as the callback isn’t even being called.

Hi @adamjrobbo,

That table called “notification” with the “iphone” and “types” child tables should go within your config.lua file, not build.settings. That might not fix the specific issue, but start there and see what happens.

Here’s the guide again for reference:

https://docs.coronalabs.com/guide/events/appNotification/index.html

Brent

Just quickly tried it and now i am getting the pop-up come up in IOS, so i think I can take it from there.

Thanks, i would have taken me ages to spot that, a fresh set of eyes is all it takes sometimes!

Just an update. got most of it working. but have a curious issue.

Built project fine to x code simulator. Got the popup to come up and it goes through the motions until the message its unsupported on this platform. The app also displays in settings with the pus options.

Now I have come to build it on an old iPhone 4 (IOS7) and when built and ran, i don’t get the pop-up asking if i want to enable push notifications, nor does the app appear in settings. However the app proceeded to register itself into my database, and using my php scripts i was able to send a push notifcation to the app, without actually accepting it using apples pop-ups.

Now i presume if i sent this off to apple it would fail its checks.

Is this a bug with corona, or am I perhaps missing something.

I have an iphone 6 which I will try it out on when i get chance; but i’m guessing it maybe a corona/IOS issue?

Update: Works fine on iPhone 6. As I suspected, seems to be an issue with Corona on IOS7?

Hi @adamjrobbo,

We’ll almost certainly need to see your code regarding this, as simplified as you can make it. Please remember to surround it with “lua” tags for clarity in the forum post.

[lua] --code [/lua]

Thanks,

Brent

Sure,

Build Settings:

[lua]

    plugins =

    {

        [“plugin.notifications”] =

        {

            publisherId = “com.coronalabs”

        },

    }, 

    notification = 

    {

        iphone =

        {

            types = { “badge”, “sound”, “alert” }

        }

    }

[/lua]

Top of main.lua

[lua]

local notifications = require( “plugin.notifications” )

notifications.registerForPushNotifications()

local launchArgs = …

if ( launchArgs and launchArgs.notification ) then

    print( launchArgs.notification.type )

    print( launchArgs.notification.name )

    print( launchArgs.notification.sound )

    print( launchArgs.notification.alert )

    print( launchArgs.notification.badge )

    print( launchArgs.notification.applicationState )

end

local json = require(“json”)

local deviceToken

local function notificationListener( event )

        print( “notification engine started!” )

      if ( event.type == “remote” and event.applicationState == “active” ) then

        --handle the push or local notification

        print( "type ", event.type ) 

        print ("event alert ", event.alert ) 

    elseif ( event.type == “remoteRegistration” ) then

        local deviceToken = event.token

        --local deviceType = 1  --default to iOS

        print( “Event Token is” … " " … event.token )

    end

end

– The notification Runtime listener should be handled from within “main.lua”

Runtime:addEventListener( “notification”, notificationListener )

[/lua]

I am planning on implementing my own push server, however i have stripped all the code from the remoteregister callback for now as the callback isn’t even being called.

Hi @adamjrobbo,

That table called “notification” with the “iphone” and “types” child tables should go within your config.lua file, not build.settings. That might not fix the specific issue, but start there and see what happens.

Here’s the guide again for reference:

https://docs.coronalabs.com/guide/events/appNotification/index.html

Brent

Just quickly tried it and now i am getting the pop-up come up in IOS, so i think I can take it from there.

Thanks, i would have taken me ages to spot that, a fresh set of eyes is all it takes sometimes!

Just an update. got most of it working. but have a curious issue.

Built project fine to x code simulator. Got the popup to come up and it goes through the motions until the message its unsupported on this platform. The app also displays in settings with the pus options.

Now I have come to build it on an old iPhone 4 (IOS7) and when built and ran, i don’t get the pop-up asking if i want to enable push notifications, nor does the app appear in settings. However the app proceeded to register itself into my database, and using my php scripts i was able to send a push notifcation to the app, without actually accepting it using apples pop-ups.

Now i presume if i sent this off to apple it would fail its checks.

Is this a bug with corona, or am I perhaps missing something.

I have an iphone 6 which I will try it out on when i get chance; but i’m guessing it maybe a corona/IOS issue?

Update: Works fine on iPhone 6. As I suspected, seems to be an issue with Corona on IOS7?