Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pathForGroup method #246

Merged
merged 3 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ var RNFS = {
return RNFSManager.pathForBundle(bundleNamed);
},

pathForGroup(groupName: string): Promise<string> {
return RNFSManager.pathForGroup(groupName);
},

getFSInfo(): Promise<FSInfoResult> {
return RNFSManager.getFSInfo();
},
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Native filesystem access for react-native

First you need to install react-native-fs:

```javascript
```
npm install react-native-fs --save
```

Expand Down Expand Up @@ -571,6 +571,17 @@ type FSInfoResult = {
};
```

### (iOS only) `pathForGroup(groupIdentifier: string): Promise<string>`

`groupIdentifier` (`string`) Any value from the *com.apple.security.application-groups* entitlements list.

Returns the absolute path to the directory shared for all applications with the same security group identifier.
This directory can be used to to share files between application of the same developer.

Invalid group identifier will cause a rejection.

For more information read the [Adding an App to an App Group](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19) section.

## Test / Demo app

Test app to demostrate the use of the module. Useful for testing and developing the module:
Expand Down
13 changes: 13 additions & 0 deletions RNFSManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,19 @@ - (dispatch_queue_t)methodQueue
}
}

RCT_EXPORT_METHOD(pathForGroup:(nonnull NSString *)groupId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSURL *groupURL = [[NSFileManager defaultManager]containerURLForSecurityApplicationGroupIdentifier: groupId];

if (!groupURL) {
return reject(@"ENOENT", [NSString stringWithFormat:@"ENOENT: no directory for group '%@' found", groupId], nil);
} else {
resolve([groupURL path]);
}
}

RCT_EXPORT_METHOD(getFSInfo:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
unsigned long long totalSpace = 0;
Expand Down
7 changes: 6 additions & 1 deletion android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,12 @@ public void stopDownload(int jobId) {

@ReactMethod
public void pathForBundle(String bundleNamed, Promise promise) {
// TODO: Not sure what equilivent would be?
// TODO: Not sure what equivalent would be?
}

@ReactMethod
public void pathForGroup(String bundleNamed, Promise promise) {
// TODO: Not sure what equivalent would be?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to reject this promise with a meaningful error message

}

@ReactMethod
Expand Down