diff --git a/packages/camera/camera_avfoundation/CHANGELOG.md b/packages/camera/camera_avfoundation/CHANGELOG.md index 91070297346e..d61722937c24 100644 --- a/packages/camera/camera_avfoundation/CHANGELOG.md +++ b/packages/camera/camera_avfoundation/CHANGELOG.md @@ -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. diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift b/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift index 7f8cef124d6f..11bda3f8b71f 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/PhotoCaptureTests.swift @@ -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) + } } diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift index d0adf655ea05..06b570582254 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift @@ -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 diff --git a/packages/camera/camera_avfoundation/pubspec.yaml b/packages/camera/camera_avfoundation/pubspec.yaml index bc6d1928fb4d..784e372c542d 100644 --- a/packages/camera/camera_avfoundation/pubspec.yaml +++ b/packages/camera/camera_avfoundation/pubspec.yaml @@ -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