Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for blank Title or Message #33

Open
edborden opened this issue May 21, 2015 · 7 comments
Open

Allow for blank Title or Message #33

edborden opened this issue May 21, 2015 · 7 comments

Comments

@edborden
Copy link

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

@EddyVerbruggen
Copy link

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

@edborden
Copy link
Author

Only tested on Android 5

@EddyVerbruggen
Copy link

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

  • Title & Message: OK
  • Message only: OK
  • Title only: no push is received on the device

Is this what you're seeing as well?

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

@edborden
Copy link
Author

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
Copy link

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
Copy link

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
Copy link
Author

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`

@edborden edborden reopened this May 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants