Skip to content

Commit 2437f8e

Browse files
committed
[birdofpreyru#28] iOS/macOS: Fixes the handling of security scopes by pickFile() and other methods
1 parent 9fe2011 commit 2437f8e

File tree

6 files changed

+166
-86
lines changed

6 files changed

+166
-86
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,18 @@ crash the app.
855855
allowing a direct access to them with other methods in this library
856856
(_e.g._ [readFile()]), even if the file is outside the app sandbox.
857857

858+
**NOTE:** On **iOS** & **macOS** it resolve to special values with the format
859+
&laquo;`bookmark://<BASE64_ENCODED_STRING>`&raquo;, rather than normal URIs.
860+
It is necessary for the support of security scopes
861+
(see [Bookmarks and Security Scopes](https://developer.apple.com/documentation/foundation/nsurl#1663783)) in library methods. The &laquo;`<BASE64_ENCODED_STRING>`&raquo;
862+
in this case is a Base64-encoded binary representation of the URL bookmark,
863+
along with its security scope data. Other methods of the library are expected
864+
to automatically handle such special URIs as needed.
865+
866+
**BEWARE:** It has not been thoroughly verified yet that all library methods
867+
support these &laquo;Bookmark URLs&raquo; correctly. The expected error in
868+
such case is a failure to access the URLs as non-existing.
869+
858870
### read()
859871
[read()]: #read
860872
```ts

example/ios/Podfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- boost (1.83.0)
33
- CocoaAsyncSocket (7.6.5)
44
- DoubleConversion (1.1.6)
5-
- dr-pogodin-react-native-fs (2.22.1):
5+
- dr-pogodin-react-native-fs (2.22.2):
66
- glog
77
- hermes-engine
88
- RCT-Folly (= 2022.05.16.00)
@@ -1402,7 +1402,7 @@ SPEC CHECKSUMS:
14021402
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
14031403
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
14041404
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
1405-
dr-pogodin-react-native-fs: 60d98fc542ed310f57d9b497628f6e72fa2d5e2a
1405+
dr-pogodin-react-native-fs: 6aaacfa553d2a4be14cf32e4053725b7057155ee
14061406
dr-pogodin-react-native-static-server: a0ab88663817dfc8791b3e88295d0d9b6d212c5f
14071407
FBLazyVector: fbc4957d9aa695250b55d879c1d86f79d7e69ab4
14081408
Flipper: c7a0093234c4bdd456e363f2f19b2e4b27652d44
@@ -1468,4 +1468,4 @@ SPEC CHECKSUMS:
14681468

14691469
PODFILE CHECKSUM: 2673e1121fca9666d2df5c7ba3b5b287e79ba95f
14701470

1471-
COCOAPODS: 1.14.3
1471+
COCOAPODS: 1.15.0

example/src/TestBaseMethods.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ const tests: { [name: string]: StatusOrEvaluator } = {
919919
} else {
920920
if (
921921
!isMatch(e, {
922-
code: 'ENSCOCOAERRORDOMAIN260',
922+
code: 'NSCocoaErrorDomain:260',
923923
message:
924924
'The file “non-existing-file.txt” couldn’t be opened because there is no such file.',
925925
})

ios/RNFSException.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
- (RNFSException*) log;
77
- (void) reject:(RCTPromiseRejectBlock)reject;
88
- (void) reject:(RCTPromiseRejectBlock)reject details:(NSString*)details;
9-
+ (RNFSException*) from: (NSException*)exception;
9+
10+
+ (RNFSException*) fromError:(NSError*)error;
11+
+ (RNFSException*) fromException:(NSException*)exception;
12+
1013
+ (RNFSException*) name: (NSString*)name;
1114
+ (RNFSException*) name: (NSString*)name details: (NSString*)details;
1215

ios/RNFSException.mm

+12-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ - (void) reject: (RCTPromiseRejectBlock)reject details: (NSString*) details
4040
reject(self.name, reason, [self error]);
4141
}
4242

43-
+ (RNFSException*) from: (NSException*)exception
43+
+ (RNFSException*) fromError:(NSError *)error
44+
{
45+
NSString *name = [NSString stringWithFormat:@"%@:%ld",
46+
error.domain, error.code];
47+
return [[RNFSException alloc]
48+
initWithName:name
49+
reason:error.localizedDescription
50+
userInfo:error.userInfo];
51+
}
52+
53+
+ (RNFSException*) fromException:(NSException *)exception
4454
{
4555
return [[RNFSException alloc]
4656
initWithName: exception.name
4757
reason: exception.reason
48-
userInfo: exception.userInfo
49-
];
58+
userInfo: exception.userInfo];
5059
}
5160

5261
+ (RNFSException*) name: (NSString*)name

0 commit comments

Comments
 (0)