Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[path_provider] Migrated path_provider_ios to pigeon. #5944

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.10

* Switches backend to pigeon.

## 2.0.9

* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -512,6 +512,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -533,6 +534,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,41 @@
// found in the LICENSE file.

#import "FLTPathProviderPlugin.h"
#import "messages.g.h"

NSString *GetDirectoryOfType(NSSearchPathDirectory dir) {
static NSString *GetDirectoryOfType(NSSearchPathDirectory dir) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
return paths.firstObject;
}

@interface FLTPathProviderPlugin () <FLTPathProviderApi>
@end

@implementation FLTPathProviderPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/path_provider_ios"
binaryMessenger:registrar.messenger];
[channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
if ([@"getTemporaryDirectory" isEqualToString:call.method]) {
result([self getTemporaryDirectory]);
} else if ([@"getApplicationDocumentsDirectory" isEqualToString:call.method]) {
result([self getApplicationDocumentsDirectory]);
} else if ([@"getApplicationSupportDirectory" isEqualToString:call.method]) {
result([self getApplicationSupportDirectory]);
} else if ([@"getLibraryDirectory" isEqualToString:call.method]) {
result([self getLibraryDirectory]);
} else {
result(FlutterMethodNotImplemented);
}
}];
}

+ (NSString *)getTemporaryDirectory {
return GetDirectoryOfType(NSCachesDirectory);
FLTPathProviderPlugin *plugin = [[FLTPathProviderPlugin alloc] init];
FLTPathProviderApiSetup(registrar.messenger, plugin);
}

+ (NSString *)getApplicationDocumentsDirectory {
- (nullable NSString *)getApplicationDocumentsPathWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return GetDirectoryOfType(NSDocumentDirectory);
}
Comment on lines +23 to 26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand if you don't want to mess with this in this PR, but if this is switched to the NSFileManager API then we actually could pass back a useful error:

[NSFileManager.defaultManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];

create:YES because I see the comment:

      // Ensure the directory exists before returning it, for consistency with
      // other platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, sounds like a good idea. Since there is no issue with the current implementation and it isn't deprecated I think we shouldn't touch it though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I moved this logic to Dart when I switched macOS to an internal method channel; we could easily do the same for iOS.


+ (NSString *)getApplicationSupportDirectory {
- (nullable NSString *)getApplicationSupportPathWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return GetDirectoryOfType(NSApplicationSupportDirectory);
}

+ (NSString *)getLibraryDirectory {
- (nullable NSString *)getLibraryPathWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return GetDirectoryOfType(NSLibraryDirectory);
}

- (nullable NSString *)getTemporaryPathWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
return GetDirectoryOfType(NSCachesDirectory);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;
@protocol FlutterMessageCodec;
@class FlutterError;
@class FlutterStandardTypedData;

NS_ASSUME_NONNULL_BEGIN

/// The codec used by FLTPathProviderApi.
NSObject<FlutterMessageCodec> *FLTPathProviderApiGetCodec(void);

@protocol FLTPathProviderApi
- (nullable NSString *)getTemporaryPathWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable NSString *)getApplicationSupportPathWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable NSString *)getLibraryPathWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable NSString *)getApplicationDocumentsPathWithError:
(FlutterError *_Nullable *_Nonnull)error;
@end

extern void FLTPathProviderApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLTPathProviderApi> *_Nullable api);

NS_ASSUME_NONNULL_END
138 changes: 138 additions & 0 deletions packages/path_provider/path_provider_ios/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// 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.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "messages.g.h"
#import <Flutter/Flutter.h>

#if !__has_feature(objc_arc)
#error File requires ARC to be enabled.
#endif

static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error) {
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
if (error) {
errorDict = @{
@"code" : (error.code ?: [NSNull null]),
@"message" : (error.message ?: [NSNull null]),
@"details" : (error.details ?: [NSNull null]),
};
}
return @{
@"result" : (result ?: [NSNull null]),
@"error" : errorDict,
};
}

@interface FLTPathProviderApiCodecReader : FlutterStandardReader
@end
@implementation FLTPathProviderApiCodecReader
@end

@interface FLTPathProviderApiCodecWriter : FlutterStandardWriter
@end
@implementation FLTPathProviderApiCodecWriter
@end

@interface FLTPathProviderApiCodecReaderWriter : FlutterStandardReaderWriter
@end
@implementation FLTPathProviderApiCodecReaderWriter
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
return [[FLTPathProviderApiCodecWriter alloc] initWithData:data];
}
- (FlutterStandardReader *)readerWithData:(NSData *)data {
return [[FLTPathProviderApiCodecReader alloc] initWithData:data];
}
@end

NSObject<FlutterMessageCodec> *FLTPathProviderApiGetCodec() {
static dispatch_once_t sPred = 0;
static FlutterStandardMessageCodec *sSharedObject = nil;
dispatch_once(&sPred, ^{
FLTPathProviderApiCodecReaderWriter *readerWriter =
[[FLTPathProviderApiCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}

void FLTPathProviderApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLTPathProviderApi> *api) {
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.PathProviderApi.getTemporaryPath"
binaryMessenger:binaryMessenger
codec:FLTPathProviderApiGetCodec()];
if (api) {
NSCAssert(
[api respondsToSelector:@selector(getTemporaryPathWithError:)],
@"FLTPathProviderApi api (%@) doesn't respond to @selector(getTemporaryPathWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api getTemporaryPathWithError:&error];
callback(wrapResult(output, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath"
binaryMessenger:binaryMessenger
codec:FLTPathProviderApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getApplicationSupportPathWithError:)],
@"FLTPathProviderApi api (%@) doesn't respond to "
@"@selector(getApplicationSupportPathWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api getApplicationSupportPathWithError:&error];
callback(wrapResult(output, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.PathProviderApi.getLibraryPath"
binaryMessenger:binaryMessenger
codec:FLTPathProviderApiGetCodec()];
if (api) {
NSCAssert(
[api respondsToSelector:@selector(getLibraryPathWithError:)],
@"FLTPathProviderApi api (%@) doesn't respond to @selector(getLibraryPathWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api getLibraryPathWithError:&error];
callback(wrapResult(output, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath"
binaryMessenger:binaryMessenger
codec:FLTPathProviderApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(getApplicationDocumentsPathWithError:)],
@"FLTPathProviderApi api (%@) doesn't respond to "
@"@selector(getApplicationDocumentsPathWithError:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
NSString *output = [api getApplicationDocumentsPathWithError:&error];
callback(wrapResult(output, error));
}];
} else {
[channel setMessageHandler:nil];
}
}
}
124 changes: 124 additions & 0 deletions packages/path_provider/path_provider_ios/lib/messages.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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.
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name
// @dart = 2.12
import 'dart:async';
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;

import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
import 'package:flutter/services.dart';

class _PathProviderApiCodec extends StandardMessageCodec {
const _PathProviderApiCodec();
}

class PathProviderApi {
/// Constructor for [PathProviderApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
PathProviderApi({BinaryMessenger? binaryMessenger})
: _binaryMessenger = binaryMessenger;

final BinaryMessenger? _binaryMessenger;

static const MessageCodec<Object?> codec = _PathProviderApiCodec();

Future<String?> getTemporaryPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.PathProviderApi.getTemporaryPath', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
} else {
return (replyMap['result'] as String?);
}
}

Future<String?> getApplicationSupportPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
} else {
return (replyMap['result'] as String?);
}
}

Future<String?> getLibraryPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.PathProviderApi.getLibraryPath', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
} else {
return (replyMap['result'] as String?);
}
}

Future<String?> getApplicationDocumentsPath() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(null) as Map<Object?, Object?>?;
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
details: error['details'],
);
} else {
return (replyMap['result'] as String?);
}
}
}
Loading