last day (14 days later) » 

4:52 AM
0
A: Play Push Notification Sound Effect when app is not running (Mac)

l'L'lIt's quite simple to implement the custom sound capability for Apple Push Notifications; the problem is that the documentation does not mention what is required to do this. The critical component that is required is an extension — (eg. using the Today Extension). Creating a new target in your pr...

 
So do I need to actually build out the today widget? Is there a trick to shipping the extension without users being able to install the widget in a broken state? I don't really want to build out a full featured widget just to get sounds to play.
 
I think it just needs to be an extension, which would include the NotificationCenter.framework within it. I know that at one point that there was actually something in that regard written in the documentation, although it was very generic terminology. It basically suggested that the extension is how your app interfaces with notifications while it's not running; maybe try just including the framework in your app without any extension — I haven't actually tried it.
SmartMailOSXShareExtension in "plugins" is likely how notifications are handled while the app is not running. grepping the extension or any of the frameworks all have references to NotificationCenter...
 
I gave it a try with a today extension, didn't seem to work. Hell, it's not even playing the right sound when I receive the notification in the foreground. I even borrowed the sound file that plays for Spark, so it isn't the file itself. Something is really odd. I may try a share extension which seems easier to hide.
 
Well, I have no idea what your project looks like or how you have the certificates setup, etc. Feel free to throw a demo project together and I'll look at it. If you have several copies of projects using the same certificates though it's bound not to work correctly. It worked perfect for me when I setup a new app, added the extension, copied the sound file to it, and used just those functions in my answer in the main app.
 
I have it all set up right. I'm using NWPusher to send myself notifications via Apple's APNS service. So I'm getting notifications, but it doesn't want to play any sound other than the default sound. If I leave the sound part off the payload, nothing plays. So obviously it is smart enough to play or not... just not smart enough to use my sound file.
 
4:52 AM
hi
 
hey, thanks for all the help so far.
 
NWPusher can sometimes be flaky also
oh you're welcome!
I think we can get it working for you
 
i'm seeing the same results whether i use Pusher or have Amazon send it to me.
 
I can zip up my project if you feel like taking a look at it.
 
were you able to get the notifications to play when the app wasn't running?
 
4:55 AM
yes, it works exactly like it's supposed to
 
how are you registering for notifications?
NSApp.registerForRemoteNotifications(matching: [.alert, .sound, .badge])
i'm getting all the right notification callbacks after registration, and push notifications are showing up. So we should be safe in assuming that my certs are ok and registration is ok.
 
yep
 
Next is my sound file. It's the same one I use in my matching iOS app, using .caf format.
It is in the application and shows up in Copy Bundle Resources.
 
Actually try using NSApplication.shared().registerForRemoteNotifications(matching: [.alert, .sound, .badge])
 
Same thing.
 
5:01 AM
That's very weird.
I'm happy to .zip mine up if you want...
 
tell me about it.
yeah, i can take a look to see what is different.
 
alright give me a couple minutes...
 
yep... need to jump out of here for a minute, brb (2 mins)
back
you'll want to change the bundle Id and create a certificate for it.
btw - it crashes with the badge if it's not a string - so make the request like:
{"aps":{"alert":"Testing.. (0)","badge":"1","sound":"arugh.wav"}}
 
5:18 AM
yeah, will need to create certs to get push to see if it is working.
i got it to compile and run, but probably a bit of work to create provisioning with push certs.
 
yeah, that's the worst part
i can do it in less than two minutes usually...
only the main app needs it.
and the main app is the only one that needs "push notification" entitlement enabled also.
 
also, given the today extension shows up... still not the likely scenario.
If you remove your today extension, you don't get the custom sound to play at all?
 
no it plays the standard one
default
 
whether the app is running or not.
 
no, if the app is running it will play the custom one (i think).
but i had different code in the main app for that.
i ripped it out for these purposes...
 
5:22 AM
yeah, i could detect when it got a notificaiton and could manually play, but if there is a sound in the payload, it would do both. So it seems to me that the app should pick the sound it should play and do that. Just happens to be using default since it can't find/see my sound.
 
yes, i noticed that as well, and another reason why i took the sound functions out of the main app.
 
yeah, according to docs (and iOS) it should just play the sound from the bundle if it can find a match.
and my test notifications will not play sound if I remove it from the payload... so it is somewhat working.
and that behavior is consistent whether the app is running or not.
 
yes, i think the person assigned to implement the mac functionality must not of been to motivated.
 
haha
well, i'm off to bed. I plan on spending some time on this tomorrow, so I'll ping you if I manage to get it going. I'll take a look at trying to work it in with the extension.
 
it basically looks like they did as little as possible to get it working
 
5:27 AM
yeah... somewhat new functionality. the old docs said that it doesn't support anything but badging in the background.
 
okay, sounds good. i'll wait to hear back from you... hopefully there will be good news on your end. :)
 
i initially didn't even try to add push here. it wasn't until I saw other apps doing it and looked into it myself that i got it working most of the way.
yeah. thanks a lot, i really appreciate it. i'll keep you posted.
 
well if/when it works it can be nice :)
good night
 
yeah, no kidding. night!
 

last day (14 days later) »