Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing App code from Notification Service Extension

Notification Service Extension modifies the content of a remote notification before it's delivered to the user. For example if a remote notification contains an image URL, Notification Service Extension can be used to fetch the image and show it in the notification content.

But how can I access actual app code in Notification Service Extension? Let's say I have a DataAccess swift class in app code, can I access this class in Notification Service Extension?

Edit: Some folks suggested to add app code to service extension, which is not applicable in my situation.

like image 226
Ramazan Polat Avatar asked Apr 29 '26 21:04

Ramazan Polat


2 Answers

Go to the classes that you want to use in your app project. On your File inspector your are gonna see the Target Membership of your class. Check the extension's name checkbox. Then you can reuse your code.

You can also add the classes you need in the Build Phases -> Compiled Sources in your notification service target. The result is the same.

like image 79
alecnash Avatar answered May 01 '26 11:05

alecnash


The usual solution is to create a library/framework which includes your DataAccess class, and your app and the Notification Service Extension uses this library/framework. Make sure you select Do not embed for your framework when adding to Notification Service Extension, and select Embed and sign when adding it to your app.

like image 43
BoygeniusDexter Avatar answered May 01 '26 10:05

BoygeniusDexter