Group Group Group Group Group Group Group Group Group

Push Notifications Tutorial for iOS: Rich Push Notifications |

Learn how to modify and enhance push notifications before they are presented to the user, how to create custom UI around your push content, and more!

This is a companion discussion topic for the original entry at

Excellent tutorial I really appreciated. However, I would have appreciated that the server side is in php. It would have been the only tutorial about an independent server.

Anyway, tanks a lot for that super work.

Hi Mark,
Awesome tutorial. Thank you

I have seen three different tutorials on RW for service extension.
one use dataTask another is uses downloadTask and another is just using Data(contentsOf: url).

I’m confused as to which I should be using. All three currently work for me, but considering weird bugs reported online that images sometimes don’t get downloaded I wonder which approach offers best solution.

Any idea?

Also what is the reason to use an App Group? I watched the WWDC videos and as long as you download and attach the image to the notification then it should work

@ski081 Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @xhome_ios. All 3 approaches are valid. Really, it’s just a matter of choosing which one fits the scenario you are coding for. I chose using a data task because it’s simple, easy to understand, and widely used. The reports online of the service extension failing could be for a variety of reasons. The extension only gets a short amount of processing time to do its work, so if anything takes too long (spotty network connection, asset excessively large), the task could fail and the image will not download properly.

I hope this helps!


I’m sorry, I’m not used to the RW’s messaging system. Just noticed your reply.

Got it. Thank you. I have 2 followup questions

Q1: If all I do in notification service extension is that I download the image, then does the provisioning profile of the service extension need any certain capabilities? Like Background task or push notifications?

I’ve added logs every where. So far without any capabilities added I have a 95% success rate, but I sometimes get -1001 (timeout error) status code for the network calls I make. Which I assume is kinda expected.

I also occasionally see 513 error from the file directory.

Q2: [“NSUnderlyingError”: Error Domain=NSPOSIXErrorDomain Code=1 “Operation not permitted”, “NSFilePath”: /private/var/mobile/Containers/Data/PluginKitPlugin/FE37CB44-E7C3-497D-95B2-45091619EF80/tmp/FE4D866A-2627-4499-9A5D-2832C39C7296-204-0000000751635A88/image]

Do you have any idea about the 513 error?

Hi @xhome_ios.

  1. No, you should not need any additional permissions outside of what I outlined in the tutorial.
  2. I’ve not seen that error before, and it seems like an underlying iOS error. There are a lot of factors that could come into play here, including network latency, and that, coupled with the time the operating system is giving you to complete your work could be creating this issue. I’m sorry I don’t have any additional troubleshooting steps, especially if this is an intermittent error.

@ski081 I figured it out :smiley:

  • turn off your phone
  • turn it on
  • don’t enter password ie don’t unlock it. At this point the device is a completeUntilFirstUserAuthentication and you can’t create a directory…
  • receive push notification

It’s basically a security design architecture in place by Apple.

You either have to change it to:

try data.write(to: tmpFileURL, options: [.noFileProtection])

and then we’d be able to access files during boot time or in locked state.

Or just allow it to fail until user enters their password for the first time.

@xhome_ios - wow, never thought about the default protection state of the device before it’s been unlocked. Great catch, and thanks for replying back!