[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:
ivan-vanyusho
2026-02-04 20:16:19 +03:00
committed by GitHub
parent f4ea763b25
commit 3bddf2c57e
4 changed files with 44 additions and 5 deletions

View File

@@ -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.

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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