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

Commit a0b493e

Browse files
committed
Migrated path_provider_ios to pigeon.
1 parent 07891d3 commit a0b493e

File tree

12 files changed

+462
-77
lines changed

12 files changed

+462
-77
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: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,41 @@
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 () <FLTPathProviderApi>
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+
FLTPathProviderApiSetup(registrar.messenger, plugin);
3521
}
3622

37-
+ (NSString *)getApplicationDocumentsDirectory {
23+
- (nullable NSString *)getApplicationDocumentsPathWithError:
24+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
3825
return GetDirectoryOfType(NSDocumentDirectory);
3926
}
4027

41-
+ (NSString *)getApplicationSupportDirectory {
28+
- (nullable NSString *)getApplicationSupportPathWithError:
29+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
4230
return GetDirectoryOfType(NSApplicationSupportDirectory);
4331
}
4432

45-
+ (NSString *)getLibraryDirectory {
33+
- (nullable NSString *)getLibraryPathWithError:
34+
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
4635
return GetDirectoryOfType(NSLibraryDirectory);
4736
}
4837

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

0 commit comments

Comments
 (0)