And yes there was a problem with IOS opening from notification, but @troysandal awesome trick with storing them as properties and then retrieving using selectors seems to work awesomely
@ar2rsawseen Thanks for the thorough testing! Nice that it has been fixed for iOS. I think the problem then lies in the firing of the event before the listener is registered. When our app opens, we check if the user's log-in is valid using an UrlLoader action. When that completes, the main view (together with a NotificationManager) is initialized. It would be hard to do this earlier, as for the (first-time) device registration, we need some specific data. I guess I could code around this anyway, but it might be a good fix to queue the notifications until a (the first) listener for it is registered, instead of the application start event.
Aha, I see. then it must be it. then it could be fixed by making and event queue like this:
local notificationQueue ={}local mngr = NotificationManager.getSharedInstance()
mngr:addEventListener(Event.PUSH_NOTIFICATION, function(e)table.insert(notificationQueue, {id = e.id, title = e.title, message = e.message, number = e.number, custom = e.custom, didOpen = e.didOpen})end)-- and then inside UrlLoader complete eventfunction complete(e)if #notificationQueue >0then--if there is anything in notification queue, process itendend
Unfortunately in Gideros there is no built in mechanism to know when someone registered for event, all events are dispatch and forget, this way they consume much less resources and are incredibly fast
@ar2rsawseen Thanks, I will try this out. Why not table.insert(notificationQueue,e) btw? And what is didOpen? Is that the new feature to detect inside/outside app?
@Venorcis because event object is weakly referenced and may be garbage collected any time (part of making them so efficient ), thus you need to copy the data and yes didOpen is that bool to indicate if app was opened from notification, but maybe it is not so intuitive name, any better ideas? wasOpened? launched? was launched?
@ar2rsawseen The naming is not really important to me; launchedApp or something will be fine I guess. However, when trying to implement the notificationqueue, I get 'attempt to call nil value' when I try to call 'removeEventListener' on a NotificationManager.getSharedInstance(). addEventListener and hasEventListener work fine :S Any idea why?
@ar2rsawseen Since the update of the notification plug-in, it is not working for me on iOS anymore. Whatever I do, the Event.PUSH_REGISTRATION is never fired. When I add a printf to didReceiveRemoteNotification in AppDelegate, that does show something, but once again in LUA nothing ever happens (whilst app is open or outside of app). It used to work before the update, but then I don't have the didOpen flag I need. Any clues?!
@Venorcis the installation changed a lot for ios after the update, do you follow all the steps? You can send me an xCode project to try out if you want
One thing I noted that registerForPushNotifications requires a string to be passed (even if empty string), due to compatibility with Android. But any other way it seems to be working.
Did you try setting up Event.PUSH_REGISTRATION_ERROR and see if there is anything there?
@ar2rsawseen The registration works fine; it is the event on an actual push notification itself that does not seem to get fired. I just noticed I made a mistake in my earlier post on this, my apologies for that; I meant that the Event.PUSH_NOTIFICATION is never fired (not the registration). I hope you can still check this! Edit: so again everything goes fine, I'm even receiving the push notifications on the device (if app is closed), but when clicking on the notification or receiving it in-app, nothing happens on iOS (thus no event fired)
Hmm interesting, I seem to receive everything fine, even with your project Here is my test code inside main.lua
local text = TextField.new(nil, "Test")
text:setPosition(100,100)
text:setScale(4)
stage:addChild(text)
mngr:addEventListener(Event.PUSH_NOTIFICATION, function(e)print("Push notification: "..e.id)print("Title: "..e.title)print("Text: "..e.message)print("Number: "..e.number)print("Custom: "..e.custom)print("Did Open app", e.didOpen)
text:setText("Id: "..e.id)end)
So when the app opens, text gets changed to the ID of notification
How do you test it?
Do you test with player or normal app. do you try it with xCode debugger attached (app launched from xCode) or simply launched from device, etc.
The only way I don't get a notification event from app start is, if I run my app from xCode. Then close app on device and kill its process (without clicking stop on xCode) and try to start from notification.
In any other way I seem to get the notification normally (both push and local)
@ar2rsawseen Do I perhaps need to call mngr:registerForPushNotifications at all times on iOS? I only do it if I have no saved value for that right now (which happens on first registration). Edit: this is all on iOS7 btw
@ar2rsawseen Ok, testing it on iOS7 would be nice, as over 75% of all iOS devices are already on this version. Please let me know in what timespan you could do this, as again this issue is holding back an important update to our app right now. I'll try calling register every time anyway too!
@ar2rsawseen Nope, always calling mngr:registerForPushNotifications does not help. There must be some iOS7 specific issue caused by the latest update then I guesss?!
Comments
I think the problem then lies in the firing of the event before the listener is registered. When our app opens, we check if the user's log-in is valid using an UrlLoader action. When that completes, the main view (together with a NotificationManager) is initialized. It would be hard to do this earlier, as for the (first-time) device registration, we need some specific data. I guess I could code around this anyway, but it might be a good fix to queue the notifications until a (the first) listener for it is registered, instead of the application start event.
then it must be it.
then it could be fixed by making and event queue like this:
and yes didOpen is that bool to indicate if app was opened from notification, but maybe it is not so intuitive name, any better ideas?
wasOpened? launched? was launched?
and now updating github
ar2rsawseen at gmail.com
Can you try sending it again?
I took your project and just replaced Bundle ID/name to match my push certificate
and this simple code:
One thing I noted that registerForPushNotifications requires a string to be passed (even if empty string), due to compatibility with Android. But any other way it seems to be working.
Did you try setting up Event.PUSH_REGISTRATION_ERROR and see if there is anything there?
Edit: so again everything goes fine, I'm even receiving the push notifications on the device (if app is closed), but when clicking on the notification or receiving it in-app, nothing happens on iOS (thus no event fired)
Here is my test code inside main.lua
How do you test it?
Do you test with player or normal app.
do you try it with xCode debugger attached (app launched from xCode) or simply launched from device, etc.
The only way I don't get a notification event from app start is, if I run my app from xCode. Then close app on device and kill its process (without clicking stop on xCode) and try to start from notification.
In any other way I seem to get the notification normally (both push and local)
what is your test lua code?
Edit: this is all on iOS7 btw
And yes I'm calling register everytime so let me try without it