Same Singleton between App and App Extension

Hello guys,

My question is quite simple, is it possible to share a singleton class between my app and my app extension, which is actually a SiriExtension ?

I've already found "app groups" capability but it doesn't seem to work (probably because the singleton comes from outside?).

I use a framework in my app and I want to use the same framework in my app extension, and of course the same singleton (same instance).

For clarification, I would like Siri to know if the user is logged in to perform the intent in question. If not, Siri would ask the user to log in before performing an intent.

An other example if its not very clear : it is actually necessary to "activate" the framework before using it. The thing is that even if my app has activated the framework, the extension doesn't know it.

Answered by Engineer in 711696022

You can use the same class in an app and extension as long as the underyling classes are supported in both targets. The app and extension will each have their own instance in memory. The app and extension will run in different processes so they can't actually share the same singleton. The key to sharing is to use an app group to place the data in a place where both the app and extension can access it.

Accepted Answer

You can use the same class in an app and extension as long as the underyling classes are supported in both targets. The app and extension will each have their own instance in memory. The app and extension will run in different processes so they can't actually share the same singleton. The key to sharing is to use an app group to place the data in a place where both the app and extension can access it.

Same Singleton between App and App Extension
 
 
Q