5

I’m creating an App ID for a Notification Service Extension

Do I need to add any capabilities to it? Its only purpose is to download the image for the notification. I don’t think I need to.

Currently I'm able to build into my device without enabling any capabilities in Xcode. Although when I look into the provisioning profile that Xcode built itself, I see Keychain Sharing enabled.

I also saw this tutorial and the tutorial goes with enabling 'App Groups'. While this other tutorial goes with enabling App Groups along with Push notification. I don't think I need App groups because I don't need to pass any values, just updating the notification is all I need.

I didn't find anything in the docs that mentions what's the correct approach. A friend told me he got his to to work without enabling anything, so I'm very confused.

mfaani
  • 33,269
  • 19
  • 164
  • 293

1 Answers1

5

Basically, you don't need any capability for notification service extension.

  • Several of my applications work without any capability.
  • One of them use app group. I need to enable it to share the log files of main application, then load it from notification service and push it to server side when receive a silent push.
  • Few of them need keychain sharing, so that I can get the key to secure communicate with server side from notification service.
nghiahoang
  • 538
  • 4
  • 10
  • 1. An your images get downloaded all the time? 2. So technically you can share any token key with app groups but it wont be encrypted. Hence the need for key chain sharing? – mfaani Jul 05 '20 at 15:24
  • 1
    1. Yes, the downloaded image in this case can't be shared with main application. 2. Yes, but it's best practice to store the keys in keychain. One more reason, our applications often have device_id, it's a uuid generated and stored in keychain (so that when reinstall application the device_id isn't regenerated) so notification service need keychain-sharing to access it. – nghiahoang Jul 05 '20 at 15:31
  • Once you use app groups, how do you share data? You just user UserDefaults? Can you shed some light on that as well? – mfaani Aug 04 '20 at 23:22
  • Ok, wait me few minutes, i’m on my way – nghiahoang Aug 05 '20 at 05:05
  • 1. you use same app group for main application and extensions (or other applications). 2. let say the app group is com.app.group, then you use FileManager to access share directory as FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "com.app.group") – nghiahoang Aug 05 '20 at 06:13
  • Awesome. Can you also elaborate in terms of sending notifications across or using userDefaults? – mfaani Aug 05 '20 at 19:42
  • 1
    1. You can use DispatchSource to listen the file changes across processes. 2. To use the UserDefaults for sharing data across, instead of UserDefaults.standard you should use UserDefault(suiteName: "com.app.group") – nghiahoang Aug 06 '20 at 03:37