Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Gideros Notification Plugin - Page 4 — Gideros Forum

Gideros Notification Plugin

124

Comments

  • 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.
  • ar2rsawseenar2rsawseen Maintainer
    edited February 2014
    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 event
    function complete(e)
        if #notificationQueue > 0 then
            --if there is anything in notification queue, process it
        end
    end
    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 Hmm, the removeEventListener seems to work now, nevermind :P But a new notification plug-in will be available soon? ;)
  • I've updated the plugin in Gideros Labs
    and now updating github ;)
  • @ar2rsawseen Awesome, will try it out!
  • @ar2rsawseen By the way, can you add www. to the download URLs in Gideros labs? You're forced to log-in again otherwise ;)
  • @ar2rsawseen Make the links relative to the current domain then? :P
  • true, I will also add a rule to redirect only to one state website, so there won't be more confusion ;)
  • @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 ;)

    ar2rsawseen at gmail.com
  • @ar2rsawseen I did, I even double-checked that before posting yesterday. Sending you the project now ;)
  • @ar2rsawseen Hey, any progress yet? This issue is the only thing currently holding back an update to our app
  • ar2rsawseenar2rsawseen Maintainer
    Hmm, I have checked my email, even spam folder, but can't find your sent project.
    Can you try sending it again?
  • @ar2rsawseen Weird; just forwarded to you again, let me know!
  • ar2rsawseenar2rsawseen Maintainer
    Hmm, interesting
    I took your project and just replaced Bundle ID/name to match my push certificate
    and this simple code:
    mngr:addEventListener(Event.PUSH_REGISTRATION, function(e)
    	print("Push notification registered: "..e.deviceId)
    end)
     
    mngr:addEventListener(Event.PUSH_REGISTRATION_ERROR, function(e)
    	print("Could not register: "..e.error)
    end)
     
    mngr:registerForPushNotifications("")
    provides:
    Push notification registered: 4d103ddd595222b05f5e3403db790366067120e8d2f27d508874974861182ad9
    Which in the end works

    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?
  • VenorcisVenorcis Member
    edited March 2014
    @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)
  • ar2rsawseenar2rsawseen Maintainer
    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)

    what is your test lua code?
  • VenorcisVenorcis Member
    edited March 2014
    @ar2rsawseen I have this in init.lua:
    pcall(function() require "notification" end)
    if NotificationManager then -- catch early events
    	local notificationQueue = {}
    	notificationEvent = function(e)
    		table.insert(notificationQueue,{title=e.title,message=e.message,custom=e.custom,didOpen=e.didOpen})
    	end
    	mngr = NotificationManager.getSharedInstance()
    	mngr:addEventListener(Event.PUSH_NOTIFICATION,function(e) notificationEvent(e) end)
    	function getNotificationQueue()
    		local queue = {}
    		if notificationQueue then
    			for i,notification in ipairs(notificationQueue) do
    				queue[i] = notification
    			end
    			notificationQueue = nil
    		end
    		return queue
    	end
    end
    And this later on in the code (after account has been verified and such):
    local queued = getNotificationQueue()
    notificationEvent = function(e)
    	local notiValue = e.custom
    	if e.didOpen then
    		local notiTimer = Timer.new(1500,1)
    		notiTimer:addEventListener(Event.TIMER,function()
    			self:pushAction(notiValue)
    		end)
    		notiTimer:start()
    	elseif native then
    		application:vibrate()
    		local dialog = ui.AlertDialog.new()
    		dialog:setTitle("Notificatie")
    		dialog:setMessage(e.message)
    		dialog:setRightButton("Negeren")
    		dialog:setLeftButton("Bekijken")
    		dialog:addEventListener("onButtonClick",function(ev)
    			if ev.buttonIndex == 2 then self:pushAction(notiValue) end
    		end)
    		dialog:show()
    	elseif wax then
    		application:vibrate()
    		local dialog = UIAlertView:init()
    		dialog:setTitle("Notificatie")
    		dialog:setMessage(e.message)
    		dialog:addButtonWithTitle("Negeren")
    		dialog:addButtonWithTitle("Bekijken")
    		local dialogdelegate = waxInlineClass({"AlertViewDelegate" .. notiValue,protocols={"UIAlertViewDelegate"}})
    		dialogdelegate.alertView_clickedButtonAtIndex = function(_,_,index)
    			if index == 1 then self:pushAction(notiValue) end
    		end
    		dialog:setDelegate(dialogdelegate)
    		dialog:show()
    	end
    	mngr:clearPushNotifications()
    end
    for i,notification in ipairs(queued) do
    	notificationEvent(notification)
    end
    On Android, this all works fine. On iOS (running a build of my app outside of xcode or something), nothing happens on any event :(
  • VenorcisVenorcis Member
    edited March 2014
    @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
  • ar2rsawseenar2rsawseen Maintainer
    @Venorcis maybe IOS7 this is the problem, I don't have ios 7 device right now, will try to get it

    And yes I'm calling register everytime so let me try without it
  • @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?!
  • @ar2rsawseen Hey, can you provide any update on this yet?
Sign In or Register to comment.