Skip to content

Commit 4dbe524

Browse files
committed
fix(ios): support excluding privacy sensitive API usage
Closes #73
1 parent 928ccf9 commit 4dbe524

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ npm install react-native-file-access
1313
cd ios && pod install
1414
```
1515

16+
Apple restricts usage of certain privacy sensitive API calls. If you do not
17+
use disk space measurements or file timestamps, define the following variable
18+
in your Podfile to exclude restricted API calls.
19+
[More details.](https://github.com/alpha0010/react-native-file-access/issues/73)
20+
21+
```ruby
22+
$RNFANoPrivacyAPI = true
23+
```
24+
1625
If the app does not use autolinking, continue to the [manual install instructions](https://github.com/alpha0010/react-native-file-access/wiki/Manual-Installation) in the wiki.
1726

1827
### Compatibility

ReactNativeFileAccess.podspec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Pod::Spec.new do |s|
1919
s.dependency "React-Core"
2020
s.dependency "ZIPFoundation", "0.9.11"
2121

22+
if defined?($RNFANoPrivacyAPI)
23+
Pod::UI.puts "#{s.name}: Removing privacy sensitive API calls"
24+
s.pod_target_xcconfig = {
25+
"OTHER_SWIFT_FLAGS" => "-DNO_PRIVACY_API"
26+
}
27+
end
28+
2229
# Don't install the dependencies when we run `pod install` in the old architecture.
2330
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
2431
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"

ios/FileAccess.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public class FileAccess : NSObject {
126126
@objc(df:withRejecter:)
127127
public func df(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
128128
DispatchQueue.global().async {
129+
#if NO_PRIVACY_API
130+
reject("ERR", "Filesystem stat API disabled via compile time flag.", nil)
131+
#else
129132
do {
130133
let stat = try FileManager.default.attributesOfFileSystem(
131134
forPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
@@ -138,6 +141,7 @@ public class FileAccess : NSObject {
138141
} catch {
139142
reject("ERR", "Failed to stat filesystem. \(error.localizedDescription)", error)
140143
}
144+
#endif
141145
}
142146
}
143147

@@ -350,9 +354,14 @@ public class FileAccess : NSObject {
350354
private func statFile(path: String) throws -> [String : Any?] {
351355
let pathUrl = URL(fileURLWithPath: path.path())
352356
let attrs = try FileManager.default.attributesOfItem(atPath: path.path())
357+
#if NO_PRIVACY_API
358+
let lastModified = 0
359+
#else
360+
let lastModified = 1000 * (attrs[.modificationDate] as! NSDate).timeIntervalSince1970
361+
#endif
353362
return [
354363
"filename": pathUrl.lastPathComponent,
355-
"lastModified": 1000 * (attrs[.modificationDate] as! NSDate).timeIntervalSince1970,
364+
"lastModified": lastModified,
356365
"path": pathUrl.path,
357366
"size": attrs[.size],
358367
"type": self.checkIfIsDirectory(path: path).isDirectory ? "directory" : "file"

0 commit comments

Comments
 (0)