[iOS] Shared Resources for two Apps from the same developer

Is it possible that AppA and AppB which are from the same developer share some local resources on a given device.


For instance:

Can the data written by App A, be read by App B (through Shared Defaults or any other mechanism)?

The following link is to a similar question raised on stackoverlfow. I wanted to be certain thus, raising this question on Apple Dev Forums.

https://stackoverflow.com/questions/9079378/shared-resources-for-two-apps-from-the-same-developer

Yes, look into App Groups.

In addition to other methods, the standard approach is through:

1) shared space in the keychain

2) using a shared space in NSUserDefaults using something like:

https://developer.apple.com/documentation/foundation/nsuserdefaults/1409957-initwithsuitename

[[NSUserDefaults alloc] initWithSuiteName:.....

that was used extensively in early WatchKit apps

3) using shared space in iCloud, especially the key-value file which is common to all apps (on all devices) owned by the same user

Shouldn't the Key Chain be only used to share Username & Passwords?


Additionally, Is there an upper limit for the amount of data I can store for a corresponding key in the keychain?

Shouldn't the Key Chain be only used to share Username & Passwords?

It’s better to say that the keychain should be used for small amounts of security-sensitive data. A common use case is passwords, but there are other things that make sense as well (digital identities, authorisation tokens, and so on).

Additionally, Is there an upper limit for the amount of data I can store for a corresponding key in the keychain?

I don’t think there’s any hard limit but I strongly recommend that you only use the keychain for small things, say, on the order of magnitude of 10 KiB or less. The keychain is optimised for such items. Storing 1 MiB of user data in the keychain is considered very poor form.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


Thank you for your response.


I just have two follow up questions,


If I wish to share data through App Groups (2nd option mentioned by PBK)

using a shared space in NSUserDefaults using something like:

https://developer.apple.com/documentation/foundation/nsuserdefaults/1409957-initwithsuitename

[[NSUserDefaults alloc] initWithSuiteName:.....

that was used extensively in early WatchKit apps


Is there a data limit when sharing data through app groups?


Can any two apps with same (part of the same app group) Share data?

Thanks for quoting me so extensively on your question to Eskimo. I look forward to his response.

Is there a data limit when sharing data through app groups?

That depends on which specific mechanism you’re talking about:

  • NSUserDefaults is really intended for small amounts of ‘preference-ish’ data, data that you wouldn’t be too worried about if it disappeared. It’s not intended for holding large amounts of valuable data. On terms of specific limits, I don’t think there is one, but I’d generally treat it like the keychain and limit yourself to the order of magnitude of 10 KiB or less.

  • NSUbiquitousKeyValueStore is much like NSUserDefaults but it does impose a strict limit on the data size. Those limits are documented in the class reference.

  • The shared container for your app group (which you get via

    -[NSFileManagre containerURLForSecurityApplicationGroupIdentifier:]
    ) is just a location in the file system, and thus has no specific data limits other than the available disk space.

Can any two apps with same (part of the same app group) Share data?

Yes.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,

Thank you so much for the response.

I just wanted to cross verify a follow-up query regarding

Can any two apps with same (part of the same app group) Share data?

Yes.

I have tested this by adding same App Groups to Two apps that are signed with different Certificate. I was able to share data even in this case.

Thus, even in the production environment, we aren't required to sign the application with the same certificate. If Apps are part of the same app group, they can share data through that app group.


Is the above statement correct?


Best Regards,

Sandeep T D S

Thus, even in the production environment, we aren't required to sign the application with the same certificate. If Apps are part of the same app group, they can share data through that app group.

Correct.

Note that the gating factor here is the Team ID. The only way that two apps can share an app group is if they are published by the same team.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank You Eskimo.

But my colleague finds a very interesting fact that Facebook and Instagram can access the same app group.

I can’t comment on other developer’s apps.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[iOS] Shared Resources for two Apps from the same developer
 
 
Q