I am trying to share data between an objective c iOS appliation and a c# xamarin forms application using app groups.
I am setting up the initial data in the objective c project and passing the data using the shared data "clipboard" available for app groups.
This is my objective c code that initializes and posts the string.
NSString *appGroupId = @"group.sample";
NSUserDefaults *groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:appGroupId];
[groupUserDefaults setValue:offlineMsg forKey:@"RunwayRequest"];
[groupUserDefaults synchronize];
This is my c# code in a Xamarin.Forms application.
string groupName = "group.sample";
NSUserDefaults shared = new NSUserDefaults();
shared.AddSuite(groupName);
var test = shared.ValueForKey((NSString)"RunwayRequest");
It is always returning a null values but I think I am adding the string to the shared folder, but I am unable to retrieve the data in the other project.
I have added the app group identifier to both provisioning profiles. I don't think I have to add anything to the plist file but I am not positive.
Yeah, you don't have to add anything into info.plist. But there are also some details.
First, you should enable App Group Capabilities for both iOS apps on Apple Developer portal.
To sum up,
Create a App Group, suppose the Identifier is group.sample.
Create an App ID for each app separately, enable App Group Capabilities and add each App ID in the App Group.
Generate a Provisioning Profiles for each app separately. Don't forget to include the correct Certificate and physical devices you want to deploy in Profiles.
Second, add a key value for Entitlements.plist for each app. For more info, you could refer to App Groups.
After the above steps, you could deploy the each app on your iOS device and share the data with app group now.
Hope it helps!