0

I have two apps, both are in the same app group... I simply want to share a string between them for now.

 NSUserDefaults * defaultsStore = [[NSUserDefaults alloc] initWithSuiteName:@"group.my.bundle.id"];
[defaultsStore setObject:@"TEST" forKey:@"Testing"];
[defaultsStore synchronize];

In the other app which is also apart of the app group I have

 NSUserDefaults * defaultsStore = [[NSUserDefaults alloc] initWithSuiteName:@"group.my.bundle.id"];
NSString * testingString = [defaultsStore objectForKey:@"Testing"];

Nothing seems to work. I don't think I have to make a extension target since they are separate independent apps?

The defaultsStore is not null but the container object is always null..

Any help would be greatly appreciated

renners
  • 45
  • 6

3 Answers3

0

Your app group is not set correct, you arenot using correct group id initWithSuiteName:

memedina
  • 26
  • 3
0

In order to use data share between apps using App Group have to do following settings by following below steps:

1.In the Project Navigator click on the *.xcodeproj file.

  1. To the right of the Project Navigator look for Project and Targets. Under targets click on your primary target (should be the first thing under Targets). Towards the top, click on the Capabilities tab.

  2. In the App Groups section click the switch to the right to turn App Groups ON.

  3. Click on the + button and add an App Group named group.my.bundle.id. Go to the same place in your other apps and this group should now be available to select. Turn this group on for each app that will be using this shared data.

Note: Do the same for both apps to share data in between.

Read ansers here for more help: Communicating and persisting data between apps with App Groups

Also red doc here:

https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW6

Community
  • 1
  • 1
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
0

You have to enable App Groups from Targets->Compabilities. enter image description here

Here is simple tutorial.

Jayesh Thanki
  • 2,037
  • 2
  • 23
  • 32