Now this may not be a problem with the module but hopefully you'll be able to advise as to what it wrong.

I did have this working a couple of weeks ago but it seems to have stopped working now and I'm not sure where the problem lies. As far as I can tell my app code is correct and the device is registered. Also I'm not getting errors when sending the notification, but the device is not receiving any notification

Therefore I can only think maybe it is a problem with my app or a problem with the certificates. Any suggestions would be welcome as I'm a bit stuck.

Comments

haagendazs’s picture

Hey there. I'll be honest: that's a tough one, as there are some many places where it could fail. Here are a couple of ideas:

  • Check to make sure your certificate is still valid. They expire after a year
  • If your app is in the store, make sure you are using the production certificate, if it's not in the store, make sure you are using the development certificate
  • Make sure the app you're testing with has notifications enabled (in the Settings app of your device if it's an iPhone), otherwise notifications don't trigger anything
marcus178’s picture

Ok I found an example for send push notification here using php

http://lessons.runrev.com/m/4069/l/53405

and using the same certificate I'm using with this module, the php script sends the notification to my app ok.

The only think I can think of is I did switch the module to production at one point but then switched back to development when I found it did not work.

haagendazs’s picture

Assigned:Unassigned» haagendazs
Status:Active» Closed (cannot reproduce)

Hi there: That page contains pretty much the code that this module is using as well. Without knowing your exact configuration, I'm sorry to say that I won't be able to figure out what the problem is.

marcus178’s picture

What would you need to know? The site it's running on is pretty much a clean installation and I have tried the php script on the same server.

haagendazs’s picture

If you named the certificates correctly, if they are in the correct location, if you're getting any errors in your log, if your token is stored in the database ...

marcus178’s picture

The certificate is name apns-development.pem and stored in push_notifications/certificates and my token is in the database. There are no error in my log.

marcus178’s picture

Uninstalling and reinstalling the module seems to have fixed it.

marcus178’s picture

Status:Closed (cannot reproduce)» Active

Ok I have figured out what is wrong so hoping you might be able to shed some light on it.

The problem only occurs if there is more than one token in the database, so if I delete all the tokens apart the device I'm testing with it works. This is why when I did my initial testing it was just to one device and hence why it worked, after a few more devices got added it stopped working.

This problem does not occur for android, I have a couple of devices and they both receive the notifications.

Vikom’s picture

Hi! I can confirm the bug. When more than one device token is stored in the database the push notifications don't work.

Did any of you guys started working on a solution?

marcus178’s picture

I glad someone else is experiencing the same issue as thought it was just me and I'd done something wrong. It's seems odd that it only affects ios and not android. Is there any update on what could be causing this.

marcus178’s picture

Ok I have done some research and sounds like just one connection should be opened and then all the message sent but it looks like at the moment a connection is created for each token. i.e $apns = push_notifications_open_apns(); is in foreach

  // Send a push notification to every recipient.
  $stream_counter = 0;
  foreach ($tokens as $token) {
    // Open an apns connection, if necessary.
    if ($stream_counter == 0) {
      $apns = push_notifications_open_apns();
      if (!$apns) {
        $result['message'] = t('APNS connection could not be established. Check to make sure you are using a valid certificate file.');
        return $result;
      }
    }
    $stream_counter++;

so if I change to the below it works but not sure if that is exactly right

  // Send a push notification to every recipient.
  $stream_counter = 0;
      // Open an apns connection, if necessary.
    if ($stream_counter == 0) {
      $apns = push_notifications_open_apns();
      if (!$apns) {
        $result['message'] = t('APNS connection could not be established. Check to make sure you are using a valid certificate file.');
        return $result;
      }
    }
  $stream_counter++;
  foreach ($tokens as $token) {
Vikom’s picture

Thanks @marcus178!
First I thought it had something to do with the development certificate I was using. I will try your fix and see if it works for me too.

I can also add to the bug report that everything looks fine when dumping variables. I get the success response for all tokens but only the first receives a push.

haagendazs’s picture

@Vikom and marcus178: The suggested code change in #11 basically removes the re-generation of a stream context during the batch process, i.e. all push notifications are being sent out using one stream.

When I was creating this module, I wasn't able to find a clear answer on how many messages can be sent out through a single stream context. If you look at the configuration under /admin/config/services/push_notifications/configure, there is a setting for it called "Stream Context Limit". Instead of changing the code, you can also change the "Stream Context Limit" to 1 and achieve the same result, i.e. creating a new stream context for every notification that should be sent out.

Could you play around with that setting and see if that has any effect on the delivery on the notifications? I looked at the example in the URL from comment #2 (http://lessons.runrev.com/m/4069/l/53405). That example only describes the delivery of a single message, so they don't really have to deal with the batch-delivery.

Basically: could you try setting your Stream Context Limit to different values (try a really low value (1) and a really high value (50) without using the above code change) and let me know if that has any effects on delivery?

Vikom’s picture

OK, so I tested this now. Setting the "Stream Context Limit" to 1 will work for multiple devices. Any of the settings above 1 will only send to the first token in the db.

Thank you!

haagendazs’s picture

Thanks a lot for the feedback. I'll change the default value in the next version I'll release for this module to "1" for the stream context limit and add a stronger warning that it might not work with higher values. I promise that it has been and still is working with more than 1 message per stream, I'm sending about 3-5 with the same code.

haagendazs’s picture

Title:Notifications not received » Notifications not received when stream context limit is set too high for some users
Status:Active» Fixed

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.