blob: 88becf20850e32e6ab39a2327da90aca679cf63e [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:flutter/foundation.dart' show visibleForTesting;
import 'package:flutter/services.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
/// The iOS implementation of [PathProviderPlatform].
class PathProviderIOS extends PathProviderPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
MethodChannel methodChannel =
const MethodChannel('plugins.flutter.io/path_provider_ios');
/// Registers this class as the default instance of [PathProviderPlatform]
static void registerWith() {
PathProviderPlatform.instance = PathProviderIOS();
}
@override
Future<String?> getTemporaryPath() async {
return methodChannel.invokeMethod<String>('getTemporaryDirectory');
}
@override
Future<String?> getApplicationSupportPath() async {
final String? path = await methodChannel
.invokeMethod<String>('getApplicationSupportDirectory');
if (path != null) {
// Ensure the directory exists before returning it, for consistency with
// other platforms.
await Directory(path).create(recursive: true);
}
return path;
}
@override
Future<String?> getLibraryPath() async {
return methodChannel.invokeMethod<String>('getLibraryDirectory');
}
@override
Future<String?> getApplicationDocumentsPath() async {
return methodChannel
.invokeMethod<String>('getApplicationDocumentsDirectory');
}
@override
Future<String?> getExternalStoragePath() async {
throw UnsupportedError('getExternalStoragePath is not supported on iOS');
}
@override
Future<List<String>?> getExternalCachePaths() async {
throw UnsupportedError('getExternalCachePaths is not supported on iOS');
}
@override
Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
throw UnsupportedError('getExternalStoragePaths is not supported on iOS');
}
@override
Future<String?> getDownloadsPath() async {
throw UnsupportedError('getDownloadsPath is not supported on iOS');
}
}