15

I have set up App Groups for both my host app and the share extension. The identifier looks like "group.com.abc.xyzApp". Is there a way to get this string out programmatically? Also, how do I detect if app groups are set programmatically? Is trying to initialize a file container or user defaults with the app group identifier enough to know? Eg:

[[NSUserDefaults alloc] initWithSuiteName:@"group.com.abc.xyzApp"].

Shwethascar
  • 1,142
  • 9
  • 18
  • 1
    Hi @Shwethascar , Did you find solution? – W.S Jan 26 '17 at 07:27
  • @W.S no I didn't. I ended up using preset strings for the identifiers. – Shwethascar Jan 26 '17 at 19:12
  • NSString *path = [[NSBundle mainBundle] pathForResource:@"MyApplicationTargetName" ofType:@"entitlements"]; NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path]; NSArray *appGroups = [dict objectForKey:@"com.apple.security.application-groups"]; I was able to read groups array using above code. now i'm trying to find entitlements file name programatically so both WatchKit Extension and App both read it's app group programatically without hard-coded string. – W.S Jan 29 '17 at 07:41
  • 1
    @W.S I think I read that this only works in development? – SAHM May 03 '17 at 14:49
  • If you unzip you ipa file, you will get a file named **embedded.mobileprovision**; the command `security cms -Di embedded.mobileprovision` will tell you the app group name. I don't know how to read it programmatically. – DawnSong Feb 25 '19 at 11:31
  • @Shwethascar could be my answer your solution? check it and if it work to you, please accept it :) – Sulfkain Apr 26 '19 at 07:31

1 Answers1

9

You cannot detect if you get something programatically, but I think this is not very usefull.

Why you need to change this? by environment maybe? If so, you can do it by project variables and then add this to your info.plist

enter image description here

enter image description here

Later you can get it with:

main.object(forInfoDictionaryKey: "AppGroupId") as? String

Hope this helps

Sulfkain
  • 5,082
  • 1
  • 20
  • 38