alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
307 stars 19 forks source link

feat(ios): add resolving Apple based app-groups directory #14

Closed MegaMaddin closed 3 years ago

MegaMaddin commented 3 years ago

Hello,

I'm currently in the process of getting rid of rn-fetch-blob due to the fact that is is being unmaintained for a while now. I stumbled across rn-file-access and like the simplicity and usage of modern languages.

To be able to switch over I need some additional features, starting with being able to resolve Apple's app-group directory for sharing content within an app-group. Please feel free to accept this pull-request.

Testing done

Since app-groups require a proper entitlement including a signing configuration, I haven't checked in that code in the example app, but will provide a code snippet for doing this.

To be able to test this change, follow those steps

  1. add the app-group entitlement in XCode and provide group.FileAccessExample as the group name
  2. select a proper signing profile to be able to use app-groups
  3. add the following code somewhere in example/src/App.tsx within the setInfo useEffect
    // AppGroups on Apple devices
    FileSystem.getAppGroupDir('group.FileAccessExample').then((groupDir) => {
      setInfo((prev) => {
        prev.push({
          key: 'getAppGroupDir(group.FileAccessExample)',
          value: groupDir,
        });

        return prev.slice();
      });
    });
  1. this should provide the following content
    getAppGroupDir(group.FileAccessExample) /Users/username/Library/Developer/CoreSimulator/Devices/DEADC0DE-BEEF-C0F3-C0FE-DEADBEEF/data/Containers/Shared/AppGroup/DEADC0DE-BEEF-C0F3-C0FE-DEADBEEF

Thanks, Martin