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

Commit 07fdffe

Browse files
committed
Migrated path_provider_ios to pigeon.
1 parent 395dc14 commit 07fdffe

File tree

9 files changed

+322
-37
lines changed

9 files changed

+322
-37
lines changed

packages/path_provider/path_provider_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.10
2+
3+
* Switches backend to pigeon.
4+
15
## 2.0.9
26

37
* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors

packages/path_provider/path_provider_ios/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 46;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -512,6 +512,7 @@
512512
"$(PROJECT_DIR)/Flutter",
513513
);
514514
INFOPLIST_FILE = Runner/Info.plist;
515+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
515516
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
516517
LIBRARY_SEARCH_PATHS = (
517518
"$(inherited)",
@@ -533,6 +534,7 @@
533534
"$(PROJECT_DIR)/Flutter",
534535
);
535536
INFOPLIST_FILE = Runner/Info.plist;
537+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
536538
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
537539
LIBRARY_SEARCH_PATHS = (
538540
"$(inherited)",

packages/path_provider/path_provider_ios/ios/Classes/FLTPathProviderPlugin.m

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,37 @@
33
// found in the LICENSE file.
44

55
#import "FLTPathProviderPlugin.h"
6+
#import "messages.g.h"
67

7-
NSString *GetDirectoryOfType(NSSearchPathDirectory dir) {
8+
static NSString *GetDirectoryOfType(NSSearchPathDirectory dir) {
89
NSArray *paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
910
return paths.firstObject;
1011
}
1112

13+
@interface FLTPathProviderPlugin () <FLTPathProvider>
14+
@end
15+
1216
@implementation FLTPathProviderPlugin
1317

1418
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
15-
FlutterMethodChannel *channel =
16-
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/path_provider_ios"
17-
binaryMessenger:registrar.messenger];
18-
[channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
19-
if ([@"getTemporaryDirectory" isEqualToString:call.method]) {
20-
result([self getTemporaryDirectory]);
21-
} else if ([@"getApplicationDocumentsDirectory" isEqualToString:call.method]) {
22-
result([self getApplicationDocumentsDirectory]);
23-
} else if ([@"getApplicationSupportDirectory" isEqualToString:call.method]) {
24-
result([self getApplicationSupportDirectory]);
25-
} else if ([@"getLibraryDirectory" isEqualToString:call.method]) {
26-
result([self getLibraryDirectory]);
27-
} else {
28-
result(FlutterMethodNotImplemented);
29-
}
30-
}];
31-
}
32-
33-
+ (NSString *)getTemporaryDirectory {
34-
return GetDirectoryOfType(NSCachesDirectory);
19+
FLTPathProviderPlugin* plugin = [[FLTPathProviderPlugin alloc] init];
20+
FLTPathProviderSetup(registrar.messenger, plugin);
3521
}
3622

37-
+ (NSString *)getApplicationDocumentsDirectory {
23+
- (nullable NSString *)getApplicationDocumentsPathWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
3824
return GetDirectoryOfType(NSDocumentDirectory);
3925
}
4026

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

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

35+
- (nullable NSString *)getTemporaryPathWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
36+
return GetDirectoryOfType(NSCachesDirectory);
37+
}
38+
4939
@end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
2+
// See also: https://pub.dev/packages/pigeon
3+
#import <Foundation/Foundation.h>
4+
@protocol FlutterBinaryMessenger;
5+
@protocol FlutterMessageCodec;
6+
@class FlutterError;
7+
@class FlutterStandardTypedData;
8+
9+
NS_ASSUME_NONNULL_BEGIN
10+
11+
12+
/// The codec used by FLTPathProvider.
13+
NSObject<FlutterMessageCodec> *FLTPathProviderGetCodec(void);
14+
15+
@protocol FLTPathProvider
16+
- (nullable NSString *)getTemporaryPathWithError:(FlutterError *_Nullable *_Nonnull)error;
17+
- (nullable NSString *)getApplicationSupportPathWithError:(FlutterError *_Nullable *_Nonnull)error;
18+
- (nullable NSString *)getLibraryPathWithError:(FlutterError *_Nullable *_Nonnull)error;
19+
- (nullable NSString *)getApplicationDocumentsPathWithError:(FlutterError *_Nullable *_Nonnull)error;
20+
@end
21+
22+
extern void FLTPathProviderSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTPathProvider> *_Nullable api);
23+
24+
NS_ASSUME_NONNULL_END
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
2+
// See also: https://pub.dev/packages/pigeon
3+
#import "messages.g.h"
4+
#import <Flutter/Flutter.h>
5+
6+
#if !__has_feature(objc_arc)
7+
#error File requires ARC to be enabled.
8+
#endif
9+
10+
static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error) {
11+
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
12+
if (error) {
13+
errorDict = @{
14+
@"code": (error.code ?: [NSNull null]),
15+
@"message": (error.message ?: [NSNull null]),
16+
@"details": (error.details ?: [NSNull null]),
17+
};
18+
}
19+
return @{
20+
@"result": (result ?: [NSNull null]),
21+
@"error": errorDict,
22+
};
23+
}
24+
static id GetNullableObject(NSDictionary* dict, id key) {
25+
id result = dict[key];
26+
return (result == [NSNull null]) ? nil : result;
27+
}
28+
static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
29+
id result = array[key];
30+
return (result == [NSNull null]) ? nil : result;
31+
}
32+
33+
34+
35+
@interface FLTPathProviderCodecReader : FlutterStandardReader
36+
@end
37+
@implementation FLTPathProviderCodecReader
38+
@end
39+
40+
@interface FLTPathProviderCodecWriter : FlutterStandardWriter
41+
@end
42+
@implementation FLTPathProviderCodecWriter
43+
@end
44+
45+
@interface FLTPathProviderCodecReaderWriter : FlutterStandardReaderWriter
46+
@end
47+
@implementation FLTPathProviderCodecReaderWriter
48+
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
49+
return [[FLTPathProviderCodecWriter alloc] initWithData:data];
50+
}
51+
- (FlutterStandardReader *)readerWithData:(NSData *)data {
52+
return [[FLTPathProviderCodecReader alloc] initWithData:data];
53+
}
54+
@end
55+
56+
NSObject<FlutterMessageCodec> *FLTPathProviderGetCodec() {
57+
static dispatch_once_t sPred = 0;
58+
static FlutterStandardMessageCodec *sSharedObject = nil;
59+
dispatch_once(&sPred, ^{
60+
FLTPathProviderCodecReaderWriter *readerWriter = [[FLTPathProviderCodecReaderWriter alloc] init];
61+
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
62+
});
63+
return sSharedObject;
64+
}
65+
66+
67+
void FLTPathProviderSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTPathProvider> *api) {
68+
{
69+
FlutterBasicMessageChannel *channel =
70+
[[FlutterBasicMessageChannel alloc]
71+
initWithName:@"dev.flutter.pigeon.PathProvider.getTemporaryPath"
72+
binaryMessenger:binaryMessenger
73+
codec:FLTPathProviderGetCodec() ];
74+
if (api) {
75+
NSCAssert([api respondsToSelector:@selector(getTemporaryPathWithError:)], @"FLTPathProvider api (%@) doesn't respond to @selector(getTemporaryPathWithError:)", api);
76+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
77+
FlutterError *error;
78+
NSString *output = [api getTemporaryPathWithError:&error];
79+
callback(wrapResult(output, error));
80+
}];
81+
}
82+
else {
83+
[channel setMessageHandler:nil];
84+
}
85+
}
86+
{
87+
FlutterBasicMessageChannel *channel =
88+
[[FlutterBasicMessageChannel alloc]
89+
initWithName:@"dev.flutter.pigeon.PathProvider.getApplicationSupportPath"
90+
binaryMessenger:binaryMessenger
91+
codec:FLTPathProviderGetCodec() ];
92+
if (api) {
93+
NSCAssert([api respondsToSelector:@selector(getApplicationSupportPathWithError:)], @"FLTPathProvider api (%@) doesn't respond to @selector(getApplicationSupportPathWithError:)", api);
94+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
95+
FlutterError *error;
96+
NSString *output = [api getApplicationSupportPathWithError:&error];
97+
callback(wrapResult(output, error));
98+
}];
99+
}
100+
else {
101+
[channel setMessageHandler:nil];
102+
}
103+
}
104+
{
105+
FlutterBasicMessageChannel *channel =
106+
[[FlutterBasicMessageChannel alloc]
107+
initWithName:@"dev.flutter.pigeon.PathProvider.getLibraryPath"
108+
binaryMessenger:binaryMessenger
109+
codec:FLTPathProviderGetCodec() ];
110+
if (api) {
111+
NSCAssert([api respondsToSelector:@selector(getLibraryPathWithError:)], @"FLTPathProvider api (%@) doesn't respond to @selector(getLibraryPathWithError:)", api);
112+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
113+
FlutterError *error;
114+
NSString *output = [api getLibraryPathWithError:&error];
115+
callback(wrapResult(output, error));
116+
}];
117+
}
118+
else {
119+
[channel setMessageHandler:nil];
120+
}
121+
}
122+
{
123+
FlutterBasicMessageChannel *channel =
124+
[[FlutterBasicMessageChannel alloc]
125+
initWithName:@"dev.flutter.pigeon.PathProvider.getApplicationDocumentsPath"
126+
binaryMessenger:binaryMessenger
127+
codec:FLTPathProviderGetCodec() ];
128+
if (api) {
129+
NSCAssert([api respondsToSelector:@selector(getApplicationDocumentsPathWithError:)], @"FLTPathProvider api (%@) doesn't respond to @selector(getApplicationDocumentsPathWithError:)", api);
130+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
131+
FlutterError *error;
132+
NSString *output = [api getApplicationDocumentsPathWithError:&error];
133+
callback(wrapResult(output, error));
134+
}];
135+
}
136+
else {
137+
[channel setMessageHandler:nil];
138+
}
139+
}
140+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Autogenerated from Pigeon (v3.1.5), do not edit directly.
2+
// See also: https://pub.dev/packages/pigeon
3+
// 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
4+
// @dart = 2.12
5+
import 'dart:async';
6+
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;
7+
8+
import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
9+
import 'package:flutter/services.dart';
10+
11+
class _PathProviderCodec extends StandardMessageCodec {
12+
const _PathProviderCodec();
13+
}
14+
15+
class PathProvider {
16+
/// Constructor for [PathProvider]. The [binaryMessenger] named argument is
17+
/// available for dependency injection. If it is left null, the default
18+
/// BinaryMessenger will be used which routes to the host platform.
19+
PathProvider({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger;
20+
21+
final BinaryMessenger? _binaryMessenger;
22+
23+
static const MessageCodec<Object?> codec = _PathProviderCodec();
24+
25+
Future<String?> getTemporaryPath() async {
26+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
27+
'dev.flutter.pigeon.PathProvider.getTemporaryPath', codec, binaryMessenger: _binaryMessenger);
28+
final Map<Object?, Object?>? replyMap =
29+
await channel.send(null) as Map<Object?, Object?>?;
30+
if (replyMap == null) {
31+
throw PlatformException(
32+
code: 'channel-error',
33+
message: 'Unable to establish connection on channel.',
34+
);
35+
} else if (replyMap['error'] != null) {
36+
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
37+
throw PlatformException(
38+
code: (error['code'] as String?)!,
39+
message: error['message'] as String?,
40+
details: error['details'],
41+
);
42+
} else {
43+
return (replyMap['result'] as String?);
44+
}
45+
}
46+
47+
Future<String?> getApplicationSupportPath() async {
48+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
49+
'dev.flutter.pigeon.PathProvider.getApplicationSupportPath', codec, binaryMessenger: _binaryMessenger);
50+
final Map<Object?, Object?>? replyMap =
51+
await channel.send(null) as Map<Object?, Object?>?;
52+
if (replyMap == null) {
53+
throw PlatformException(
54+
code: 'channel-error',
55+
message: 'Unable to establish connection on channel.',
56+
);
57+
} else if (replyMap['error'] != null) {
58+
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
59+
throw PlatformException(
60+
code: (error['code'] as String?)!,
61+
message: error['message'] as String?,
62+
details: error['details'],
63+
);
64+
} else {
65+
return (replyMap['result'] as String?);
66+
}
67+
}
68+
69+
Future<String?> getLibraryPath() async {
70+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
71+
'dev.flutter.pigeon.PathProvider.getLibraryPath', codec, binaryMessenger: _binaryMessenger);
72+
final Map<Object?, Object?>? replyMap =
73+
await channel.send(null) as Map<Object?, Object?>?;
74+
if (replyMap == null) {
75+
throw PlatformException(
76+
code: 'channel-error',
77+
message: 'Unable to establish connection on channel.',
78+
);
79+
} else if (replyMap['error'] != null) {
80+
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
81+
throw PlatformException(
82+
code: (error['code'] as String?)!,
83+
message: error['message'] as String?,
84+
details: error['details'],
85+
);
86+
} else {
87+
return (replyMap['result'] as String?);
88+
}
89+
}
90+
91+
Future<String?> getApplicationDocumentsPath() async {
92+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
93+
'dev.flutter.pigeon.PathProvider.getApplicationDocumentsPath', codec, binaryMessenger: _binaryMessenger);
94+
final Map<Object?, Object?>? replyMap =
95+
await channel.send(null) as Map<Object?, Object?>?;
96+
if (replyMap == null) {
97+
throw PlatformException(
98+
code: 'channel-error',
99+
message: 'Unable to establish connection on channel.',
100+
);
101+
} else if (replyMap['error'] != null) {
102+
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
103+
throw PlatformException(
104+
code: (error['code'] as String?)!,
105+
message: error['message'] as String?,
106+
details: error['details'],
107+
);
108+
} else {
109+
return (replyMap['result'] as String?);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)