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.
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
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’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]
No, you should not need any additional permissions outside of what I outlined in the tutorial.
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.
I am stuck at the part trying to get the notification title to change. I can get notifications to come through on my phone, but no changes to the initial notification occur. I put a print statement inside the didRecieve of the NotificationService.swift and it looks like it never gets called when I receive a notification. I’m running iOS 14.3, any ideas on what could be wrong?
Hi @filipee26. Sounds like something wrong with your configuration or with the push payload itself. I’ve seen this happen when the mutable-content entry is not set or is in the wrong place. Maybe check that?
Hi guys, thanks for this excellent tutorial! I appreciate that!
However, I am not able to get the notification service extension and the notification content extension to work. As @filipee26 says it seems that the extensions never gets called…
(No breakpoint hit after attaching / running the extension)
I downloaded the source code for the final project and updated the app values according to the Getting Started instructions but I only get the ‘normal’ notification without image and custom UI.
I suspect that there are breaking changes on Apple’s side that prevent the current approach. Can this be? I did some other tutorials but got the same result. I would be very happy to get some help.
Thanks for the tutorial, I had a quick question. Can you elaborate on why the Content Extension needs to be a part of the app group and the Service Extension does not have this step? What role does the app group play here and can this be achieved without it?
The Service Extension doesn’t offer any functionality except showing some metadata about the push and downloading the icon for display on the banner. It’s able to do this directly without reading any additional data from the app.
The Content Extension relies on reading some data from the core data store, which is shared with the iOS app. A common way to do this is to place the core data store in the app container so it is accessible by the extension and the app. In this way, both the extension and the app can read from the same data store.