ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

IOS device can not pop notification when app is in background. #233

Closed AlphaJian closed 8 years ago

AlphaJian commented 8 years ago

I finish integrating GCM into iOS. And the delegate "didReceiveRemoteNotification" can also receive notification. But my issue is when app is in background, how can device receive system push notification as other app?

hypesystem commented 8 years ago

You may need to set priority to "high" for the notifications to work while the app is in the background. This is hard to debug without you showing any code, though :smile:

AlphaJian commented 8 years ago

@hypesystem .So below is my server code:

let message = new gcm.Message()

message.addData('title', 'new message')
message.addData('message', 'message you have a task to do')
message.addData('priority', 'high')
let regTokens = ['xxxx']

// Set up the sender with you API key
let sender = new gcm.Sender('xxxxxx')

console.log(message)
// Now the sender can be used to send messages
sender.send(message, { registrationTokens: regTokens}, function(err, response) {
  if (err) console.error(err)
  else console.log(response)
})

And in my Xcode, this function

func application( application: UIApplication,
                  didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){}

really receive the message, even in back ground. But the point is, as normal app, they can receive notification in system notification center. But mine is not working.

hypesystem commented 8 years ago

I am not sure I understand exactly what is not working. Do you think you could try and explain it in more detail?

wding006 commented 8 years ago

@hypesystem what he means is, he can receive the message in the function didReceiveRemoteNotification from the client but no notification comes and we can print out the message from the userInfo. We can trigger the notification manually but as what it should be is the notification center of IOS will send the system notification, there is no need to trigger it, the problem might be the notification center can not recognize the notification?

hypesystem commented 8 years ago

Ah! In his code he is using addData to set data on the message. If you want a notification to show up automatically, you need to set the notification field (with addNotification). Follow the instructions in the README :smile:

piyushsf commented 8 years ago

I am facing the same issue even after adding notification. Please tell what should I send in notification to make it work.

Thanks!

hypesystem commented 8 years ago

@piyushsf it's hard to help unless you show some code :-) what have you tried? how does your code look?

piyushsf commented 8 years ago

It is working fine as there was some issue at my end. Thanks for the help :)

hypesystem commented 8 years ago

I am closing this issue for lack of response. If you need more help, please feel free to take it up again :-)