Telerik-Verified-Plugins / PushNotification

Push Notification Plugin for iOS and Android
MIT License
55 stars 57 forks source link

Allow for blank Title or Message #33

Open edborden opened 9 years ago

edborden commented 9 years ago

Notifications won't post to notification bar unless both fields are set.

EddyVerbruggen commented 9 years ago

On which platform are you seeing this? iOS/Android/WP/all?

edborden commented 9 years ago

Only tested on Android 5

EddyVerbruggen commented 9 years ago

Hi, just tested Android 5 and these are my observations:

Is this what you're seeing as well?

Also, how are you sending the messages? Telerik Backend, your own, etc?

edborden commented 9 years ago

Sending via Rails + GCM gem

Sending with message only, I was receiving notifications inside the app, with the app open. With the app closed or in background, nothing was being posted to the notification bar.

Sending with message & title, notifications now posted to notification bar while closed or in background.

EddyVerbruggen commented 9 years ago

Can I take a look at your code? Server and client, especially server? There must be a difference in our implementations as I can't reproduce it.

AntonDobrev commented 9 years ago

Just tested with independent server application and observed the same behavior as Eddy explained.

Title & Message: OK

"title": "title for the push", 
"message": "message for my app"

Message only: works as expected

 "message": "message for my app"

Title only: does not place the notification in the bar

"title": "title for the push" 
edborden commented 9 years ago

Server:

gem 'gcm', require: 'gcm'

class GoogleCloudHandler

    def initialize reg_id
        @key = "AIzaSyCuNmd-up-Bus9PgQ1Q3xwdKMT4drRWppM"
        @reg_id = reg_id
    end

    def client
        @client ||= GCM.new @key
    end

    def send_message subject,body
        subject = "-" unless subject
        body = "-" unless body
        options = {data: {message: body,title:subject}, collapse_key: "update"}
        client.send([@reg_id], options)
    end

end

Client:

class NotificatorService extends Ember.Service

    regId: null
    platform: null

    init: ->
        if cordova?
            @setup()
        else
            document.addEventListener "deviceready", => @setup()

        window.onNotification = Ember.run.bind @,@onNotification
        window.onNotificationAPN = Ember.run.bind @,@onNotificationAPN

    setup: ->
        pushNotification = window.plugins.pushNotification
        callbackHandler = Ember.run.bind @,@callbackHandler

        if device.platform is 'android' or device.platform is 'Android'
            @platform = 'android'
            pushNotification.register callbackHandler,callbackHandler,{"senderID":"redacted","ecb":"onNotification"}
        else
            @platform = 'ios'
            pushNotification.register callbackHandler,callbackHandler,{"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"}

    callbackHandler: (result) ->
        console.log 'RegistratorServiceCallback'
        console.log result  

    onNotificationAPN: (event) ->
        console.log event
        if event.alert
            navigator.notification.alert(event.alert)

        if event.badge 
            pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge)

    onNotification: (e) ->
        console.log e

        switch e.event
            when 'registered' then @regId = e.regid

            when 'message'
                if e.foreground
                    console.log 'app is in the foreground'
                else

                    if e.coldstart
                        console.log 'coldstart'
                    else
                        console.log 'background notification'

                console.log 'message:',e.payload.message

            when 'error'
                console.log 'error',e

`export default NotificatorService`