react-native-share 9.0.2 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/RNShare.mm +18 -1
- package/ios/RNShareUtils.h +1 -1
- package/ios/RNShareUtils.m +7 -3
- package/package.json +1 -1
package/ios/RNShare.mm
CHANGED
|
@@ -187,7 +187,9 @@ RCT_EXPORT_METHOD(open:(NSDictionary *)options
|
|
|
187
187
|
BOOL saveToFiles = [RCTConvert BOOL:options[@"saveToFiles"]];
|
|
188
188
|
NSString *filename = [RCTConvert NSString:options[@"filename"]];
|
|
189
189
|
|
|
190
|
+
NSArray *filenamesArray = options[@"filenames"];
|
|
190
191
|
NSArray *urlsArray = options[@"urls"];
|
|
192
|
+
|
|
191
193
|
for (int i=0; i<urlsArray.count; i++) {
|
|
192
194
|
NSURL *URL = [RCTConvert NSURL:urlsArray[i]];
|
|
193
195
|
if (URL) {
|
|
@@ -200,8 +202,23 @@ RCT_EXPORT_METHOD(open:(NSDictionary *)options
|
|
|
200
202
|
reject(@"no data",@"no data",error);
|
|
201
203
|
return;
|
|
202
204
|
}
|
|
205
|
+
|
|
206
|
+
//name get from array of filenames
|
|
207
|
+
@try {
|
|
208
|
+
NSString *fileNameByIndex = [RCTConvert NSString:filenamesArray[i]];
|
|
209
|
+
if(fileNameByIndex.length>0){
|
|
210
|
+
//replace filename with name get by index
|
|
211
|
+
filename=fileNameByIndex;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
@catch (NSException * e) {
|
|
215
|
+
RCTLogError(@"Exception get filename from finames array: %@", e);
|
|
216
|
+
}
|
|
217
|
+
|
|
203
218
|
if (saveToFiles) {
|
|
204
|
-
|
|
219
|
+
|
|
220
|
+
NSURL *filePath = [RNShareUtils getPathFromBase64:URL.absoluteString with:data fileName:filename];
|
|
221
|
+
|
|
205
222
|
if (filePath) {
|
|
206
223
|
[items addObject: filePath];
|
|
207
224
|
}
|
package/ios/RNShareUtils.h
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
@interface RNShareUtils : NSObject
|
|
4
4
|
+(NSString*)getExtensionFromBase64:(NSString*)base64String;
|
|
5
|
-
+(NSURL*)getPathFromBase64:(NSString*)base64String with:(NSData*)data;
|
|
5
|
+
+(NSURL*)getPathFromBase64:(NSString*)base64String with:(NSData*)data fileName:(NSString*)name;
|
|
6
6
|
+(NSURL*)getPathFromFilename:(NSString*)filename with:(NSData*)data;
|
|
7
7
|
@end
|
package/ios/RNShareUtils.m
CHANGED
|
@@ -29,17 +29,21 @@
|
|
|
29
29
|
Given a base64 string and Data, writes a temp file with a guessed extension from
|
|
30
30
|
the base mime type.
|
|
31
31
|
*/
|
|
32
|
-
+(NSURL*)getPathFromBase64:(NSString*)base64String with:(NSData*)data {
|
|
32
|
+
+(NSURL*)getPathFromBase64:(NSString*)base64String with:(NSData*)data fileName:(NSString*)name {
|
|
33
33
|
NSString * mimeType = [RNShareUtils getExtensionFromBase64:base64String];
|
|
34
|
-
|
|
34
|
+
NSString * fileName=name;
|
|
35
35
|
// default to png if invalid
|
|
36
36
|
// it was like this originally, should it default
|
|
37
37
|
// to a better file type or no extension at all?
|
|
38
38
|
if(!mimeType){
|
|
39
39
|
mimeType = @"png";
|
|
40
40
|
}
|
|
41
|
+
//default to file if invalid
|
|
42
|
+
if(!fileName){
|
|
43
|
+
fileName=@"file";
|
|
44
|
+
}
|
|
41
45
|
|
|
42
|
-
NSString *pathComponent = [NSString stringWithFormat:@"
|
|
46
|
+
NSString *pathComponent = [NSString stringWithFormat:@"%@.%@",fileName, mimeType];
|
|
43
47
|
NSString *writePath = [NSTemporaryDirectory() stringByAppendingPathComponent:pathComponent];
|
|
44
48
|
if ([data writeToFile:writePath atomically:YES]) {
|
|
45
49
|
return [NSURL fileURLWithPath:writePath];
|
package/package.json
CHANGED