Open edborden opened 9 years ago
On which platform are you seeing this? iOS/Android/WP/all?
Only tested on Android 5
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?
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.
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.
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"
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`
Notifications won't post to notification bar unless both fields are set.