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

IOS Background Notifications 'contentAvailable' #37

Open
buymybm100 opened this issue May 9, 2021 · 5 comments
Open

IOS Background Notifications 'contentAvailable' #37

buymybm100 opened this issue May 9, 2021 · 5 comments

Comments

@buymybm100
Copy link

buymybm100 commented May 9, 2021

Hi Paul,
Thanks so much for this package! I used your instructions and the example to get up and running. I am able to send notifications and receive them in pop-ups on the Mobile (outside the App). However, the CordovaPush.on("notifications") handler is not being called.

I am using your userPushNotification() meteor method .. and have the 'contentAvailable' flag set to true.
Below is the Final notification right before shoot out but content-available is not set.
....

    "payload": {
      "aps": {
        "alert": {
              "title": "You have a new Request ",
              "body": "This is a simple alert",
              "launch-image": ""
        },
        "badge": 1,
        "sound": "note.caf",
        "data": {}
      }
    }

Seems 'content-available' is needed for background notifications to work on IOS.
ref: https://github.com/havesource/cordova-plugin-push/blob/master/docs/PAYLOAD.md#ios-behaviour

I have tried hard-coding "content-available": 1 in the payload (in server/notification.js) but that didn't work either.

Have I missed something ? T

Best wishes,
Beemer

@buymybm100
Copy link
Author

Seems to be the same issue reported here : #35
ie, An exception is thrown in setBadge() in "lib/client/cordova.js"

If the code in setBadge() is hashed out , I can get notifications from the CordovaPush.push.on("notification", fn) handler.
The badge on the App icon is set correctly even with the code hashed out in setBadge().

ERROR: Unhandled Promise rejection: undefined is not a function (near '...this.once...') ; Zone: ; Task: Promise.then ; Value: TypeError: undefined is not a function (near '...this.once...') setBadge@http://localhost:12760/__cordova/packages/activitree_push.js?hash=6790efaf59ddf737434821a3c8a75eced5662294:114:16
http://localhost:12760/__cordova/packages/activitree_push.js?hash=6790efaf59ddf737434821a3c8a75eced5662294:226:32

 setBadge (count)  {
   /*---- **hashed out  temporarily** ----
    this.once('ready', () => {
      if (/ios/i.test(device.platform)) {
        this.log('PushHandle.setBadge:', count)
        // xxx: at the moment only supported on iOS
        this.push.setApplicationIconBadgeNumber(() => {
          this.log('PushHandle.setBadge: was set to', count)
        }, (e) => {
          PushEventState.emit('error', {
            type: getService() + '.cordova',
            error: 'PushHandle.setBadge Error: ' + e.message
          })
        }, count)
      }
    })
   -------- */
  }

what does setBadge() do ?

Best wishes,
Beemer

@buymybm100
Copy link
Author

Hi Paul, an update on this .. I got the 'IOS background notifications' to work after

  1. hashing out the this.once("ready") code in setBadge() ... or putting a TRY-CATCH around it so the App doesn't crash
    and
  2. hard-coding the 'content-available': 1 in the payload (in server/notification.js)

Not sure why this.once("ready") isn't working. With regards to the 'contentAvailable', this parameter is not set in the notification.js .. so, will be a quick fix.

Works with METEOR@2.2

Thanks again , your work is much appreciated !

Beemer

@aboire
Copy link

aboire commented May 11, 2021

@buymybm100
i have a question have you updated the cordova plugins?
I do not see the authorization notification on my app on ios? are they present on your app?

@buymybm100
Copy link
Author

no, i just used the cordova plugins specified in the example directory.

re: "authorization notification" - do you mean the popup message on the Mobile that ask if you allow notifications ?
Yes, i get that. It comes up after the call to CordovaPush.Configure({}).. comes up about 2-3 seconds after the call.

@rioadrian
Copy link

rioadrian commented May 20, 2022

Hi @buymybm100,
I have similar problem and able to redirect my page on notification receive when I change my payload. It's also mentioned in documentation : phonegap-push-plugin

try this one for payload (ios only):

{
    "registration_ids": [
        “this is yoour device id”
    ],
    "notification": {
        "body": “Just check it out guys, it’s cheap yet qualified!”,
        "title": “Buy Our Product Now!,
        "subtitle": “Just Stylist“,
        "sound": "default",
        "tag": "1"
    },
     "data": {
        "redirectUrl": "/merchandise/merchandiseDetail/_this_is_product_id_x7gdyneidjhma”
    },
  "content_available": true  
}

for android you must implement different payload as mentioned in the document.
I hope it can help.

Thanks & Regards

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