Skip to content

Commit fc27abd

Browse files
npomfretwkh237
authored andcommitted
added pathForAppGroup iOS function (wkh237#328)
1 parent b30a35c commit fc27abd

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

fs.js

+10
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ function mkdir(path:string):Promise {
137137

138138
}
139139

140+
/**
141+
* Returns the path for the app group.
142+
* @param {string} groupName Name of app group
143+
* @return {Promise}
144+
*/
145+
function pathForAppGroup(groupName:string):Promise {
146+
return RNFetchBlob.pathForAppGroup(groupName);
147+
}
148+
140149
/**
141150
* Wrapper method of readStream.
142151
* @param {string} path Path of the file.
@@ -366,6 +375,7 @@ export default {
366375
writeStream,
367376
writeFile,
368377
appendFile,
378+
pathForAppGroup,
369379
readFile,
370380
exists,
371381
createFile,

ios/RNFetchBlob/RNFetchBlob.m

+14
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ - (NSDictionary *)constantsToExport
184184

185185
}
186186

187+
#pragma mark - fs.pathForAppGroup
188+
RCT_EXPORT_METHOD(pathForAppGroup:(NSString *)groupName
189+
resolver:(RCTPromiseResolveBlock)resolve
190+
rejecter:(RCTPromiseRejectBlock)reject)
191+
{
192+
NSString * path = [RNFetchBlobFS getPathForAppGroup:groupName];
193+
194+
if(path) {
195+
resolve(path);
196+
} else {
197+
reject(@"RNFetchBlob file not found", @"could not find path for app group", nil);
198+
}
199+
}
200+
187201
#pragma mark - fs.exists
188202
RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callback) {
189203
[RNFetchBlobFS exists:path callback:callback];

ios/RNFetchBlobFS.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
+ (NSString *) getDocumentDir;
5353
+ (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
5454
+ (NSString *) getPathOfAsset:(NSString *)assetURI;
55+
+ (NSString *) getPathForAppGroup:(NSString *)groupName;
5556
+ (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * path, ALAssetRepresentation *asset)) onComplete;
5657

5758
// fs methods

ios/RNFetchBlobFS.m

+10
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext {
129129
return tempPath;
130130
}
131131

132+
+ (NSString *) getPathForAppGroup:(NSString *)groupName {
133+
NSFileManager* fileManager = [NSFileManager defaultManager];
134+
NSURL* containerURL = [fileManager containerURLForSecurityApplicationGroupIdentifier:groupName];
135+
if(containerURL) {
136+
return [containerURL path];
137+
} else {
138+
return nil;
139+
}
140+
}
141+
132142
#pragma margk - readStream
133143

134144
+ (void) readStream:(NSString *)uri

0 commit comments

Comments
 (0)