Open smhk opened 2 months ago
Interesting, looking into this. Are you using TypeScript or JavaScript? It seems like notification constructor is not working correctly, it should always have a default options
property which is where we read topic from. The fact that is undefined is very suspect.
Is there more code that we're not seeing here? It seems like something is removing the options property from the notification. The code here should work totally fine.
@AndrewBarba thank you so much, am using JavaScript. that is literally every line of code
I tried setting the topic "manually", things like
new Notification(aTokenData, { alert: 'apns yoyo', topic .. etc })
but I couldn't get it
more info ..
I have used (only) apns2 in the past and it always worked. (Notice my long post here! https://stackoverflow.com/a/60550859/294884 ) I haven't done push for a yr or two and I can't access the previous client projects, so dunno.
I bring up exactly like this ..
(I deliberately made wrong the various other data items, to ensure that, was not the issue; ie I would incorrectly get "wrong key" etc from Apple ... all working great)
Here the current code for it sending, live on server now, (I also tried the pink alternates extensively),
result right now when I try it ..
hopefully just some dumb mistake on my part @AndrewBarba !
thanks !!!!!
And you're using the latest version right? v11.7.0?
Yes, latest version checked!
I looked through the source https://github.com/AndrewBarba/apns2/blob/main/src/apns.ts but couldn't find any clues. Could it relate to the default for topic or defaultTopic?
Am more than happy to console.log anything that could help
I noticed there's an email on your git account so I sent along the actual runnable file, you never know
Could a problem be caused by
const { ApnsClient } = require('apns2')
rather than
import { ApnsClient } from 'apns2'
The import form doesn't work in my project.
Yeah this is what I'm focused on right now since I've only used in TypeScript and ESM projects. I'll report back with what I find
Yeah something is fishy passing in a buffer, can you try new Notification(aTokenData.toString('hex'), { alert: 'apns yoyo2' })
I doubt the array version is actually sending the token. The array variant will resolve to an array of results, and if you log those results I bet you see that there was an error. Most likely need to format the token correctly. You are creating a buffer from a base64 string, so I think you then need to do .toString('hex')
but im not 100% sure id need to see one of the tokens.
No luck with this one guys ?!
Did you trying calling toString(hex) on the buffer? You cannot pass in a buffer to the new Notification()
"TypeError: Cannot read properties of undefined (reading 'topic')"
same production or sandbox
I tried both defaultTopic and topic at the end there ?
Tears!
My code to send just ..