mirror of
https://github.com/flutter/packages.git
synced 2026-03-13 10:40:37 +08:00
[camera_avfoundation] ios saving path (#10832)
## Description
Changed iOS file storage path from `documentDirectory` to `temporaryDirectory` to ensure consistency with Android where files are stored in cache directory.
## Changes
- iOS now uses `temporaryDirectory` instead of `documentDirectory` for consistency with Android
## Code changes
```swift
// Before:
let documentDirectory = FileManager.default.urls(
for: .documentDirectory,
in: .userDomainMask)[0]
// After:
let documentDirectory = FileManager.default.temporaryDirectory
```
## Issues
https://github.com/flutter/flutter/issues/166933
## Pre-Review Checklist
**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 0.9.23
|
||||
|
||||
* Changes the default storage path for camera pictures and videos on iOS from the application's Documents directory to the system's temporaryDirectory.
|
||||
|
||||
## 0.9.22+10
|
||||
|
||||
* Handles video and audio interruptions and errors by "pausing" and reporting errors.
|
||||
|
||||
@@ -201,4 +201,41 @@ final class PhotoCaptureTests: XCTestCase {
|
||||
|
||||
waitForExpectations(timeout: 30, handler: nil)
|
||||
}
|
||||
|
||||
func testCaptureToFile_mustSavePhotoToCameraPicturesDirectory() {
|
||||
let expectedPath = "/tmp/camera/pictures/"
|
||||
let expectation = self.expectation(
|
||||
description: "Photo must be saved to \(expectedPath) directory.")
|
||||
|
||||
let captureSessionQueue = DispatchQueue(label: "capture_session_queue")
|
||||
captureSessionQueue.setSpecific(
|
||||
key: captureSessionQueueSpecificKey, value: captureSessionQueueSpecificValue)
|
||||
let cam = createCam(with: captureSessionQueue)
|
||||
|
||||
let mockOutput = MockCapturePhotoOutput()
|
||||
mockOutput.capturePhotoWithSettingsStub = { settings, photoDelegate in
|
||||
let delegate = cam.inProgressSavePhotoDelegates[settings.uniqueID]
|
||||
let ioQueue = DispatchQueue(label: "io_queue")
|
||||
ioQueue.async {
|
||||
delegate?.completionHandler(delegate?.filePath, nil)
|
||||
}
|
||||
}
|
||||
cam.capturePhotoOutput = mockOutput
|
||||
|
||||
captureSessionQueue.async {
|
||||
cam.captureToFile { filePath, error in
|
||||
XCTAssertNil(error)
|
||||
XCTAssertNotNil(filePath)
|
||||
|
||||
if let filePath = filePath {
|
||||
XCTAssertTrue(
|
||||
filePath.contains(expectedPath)
|
||||
)
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 30, handler: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,11 +746,9 @@ final class DefaultCamera: NSObject, Camera {
|
||||
subfolder: String,
|
||||
prefix: String
|
||||
) throws -> String {
|
||||
let documentDirectory = FileManager.default.urls(
|
||||
for: .documentDirectory,
|
||||
in: .userDomainMask)[0]
|
||||
let temporaryDirectory = FileManager.default.temporaryDirectory
|
||||
|
||||
let fileDirectory = documentDirectory.appendingPathComponent("camera").appendingPathComponent(
|
||||
let fileDirectory = temporaryDirectory.appendingPathComponent("camera").appendingPathComponent(
|
||||
subfolder)
|
||||
let fileName = prefix + UUID().uuidString
|
||||
let file = fileDirectory.appendingPathComponent(fileName).appendingPathExtension(ext).path
|
||||
|
||||
@@ -2,7 +2,7 @@ name: camera_avfoundation
|
||||
description: iOS implementation of the camera plugin.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
|
||||
version: 0.9.22+10
|
||||
version: 0.9.23
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.0
|
||||
|
||||
Reference in New Issue
Block a user