I was implementing push notifications into Activity Filter on iOS this afternoon when I encountered an issue that I know I have had before.
I've often used my blog as a way of reminding myself of software problems that I have historically encountered but apparently I did not write this one down.
The problem
Within the app I update my Amazon Pinpoint endpoint to associate a user ID with it. Then we can send notifications based on a user ID.
Unfortunately however when sending a test notification the API was responding with OptOut: 'ALL'
and the notification was not being received.
The simulator.
The first thing to note is that push notifications using Amazon Pinpoint do not work in the simulator.
If you have a notification related problem and you want to do it you'll need to debug it on a device.
I package up a build, upload it to iTunes Connect and debug in TestFlight.
Compare it to a working copy
I had previously set up notifications for the Training Plan iOS app. As far as I was aware they were still working.. I created a build, and checked. They were.
Activity Filter was using the exact same code for notification registration and integrating with Pinpoint (see Extracting reused components to a Framework on both Android and iOS), so I assumed that it would be a problem with some hidden XCode setting. That (it turns out correct) knowledge didn't make a resolution any quicker..
Googling
Googling led me to check that I had the correct Capabilities assigned to my app provisioning profile in iTunes Connect. I did.
I then stumbled upon post suggesting I check that I had the appropriate Required background modes
set in my Info.plist
. I did not, but this did not fix the issue.
Side by Side
I then opened my non-working Activity Filter project next to the working Training Plan project and compared them side by side.
I immediately noticed that my target did not display Push Notifications
under the Capabilities
section even though it was set on my provisioning profile shrug. I assumed this was the fix. It was not.
In my euphoria of thinking i had fixed the issue I didn't notice the additional Capability
option for Background Modes
. I eventually noticed and added the Remote notifications
background mode here and this did fix the issue.
![](https://thomasclowes.com/content/images/2021/06/background-modes-and-capabilities-ios-xcode.png)
Thoughts
So basically you (obviously) need to enable the Push Notifications capability as well as the Remote Notifications background mode.
That said, doing this from the Info.plist/Provisioning profile in iTunes connect does not seem to be the correct place to do this.
Once I had figured it out I typed into Google and stumbled upon this StackOverflow answer which I had (of course) previously upvoted when I last had this problem bangs head.