Skip to content

Commit 4dc0f40

Browse files
committed
Support ios platform
1 parent 10e110c commit 4dc0f40

11 files changed

+155
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2
2+
3+
- Support ios platform.
4+
15
## 0.1.1
26

37
- [macos & windows] Implement `getInitialUrl` metnod.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ English | [简体中文](./README-ZH.md)
2121

2222
- [protocol_handler](#protocol_handler)
2323
- [Platform Support](#platform-support)
24+
- [Desktop](#desktop)
25+
- [Mobile](#mobile)
2426
- [Quick Start](#quick-start)
2527
- [Installation](#installation)
2628
- [Usage](#usage)
@@ -34,10 +36,18 @@ English | [简体中文](./README-ZH.md)
3436

3537
## Platform Support
3638

39+
### Desktop
40+
3741
| Linux | macOS | Windows |
3842
| :---: | :---: | :-----: |
3943
|| ✔️ | ✔️ |
4044

45+
### Mobile
46+
47+
| Android | iOS |
48+
| :-----: | :---: |
49+
|| ✔️ |
50+
4151
## Quick Start
4252

4353
### Installation

ios/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.idea/
2+
.vagrant/
3+
.sconsign.dblite
4+
.svn/
5+
6+
.DS_Store
7+
*.swp
8+
profile
9+
10+
DerivedData/
11+
build/
12+
GeneratedPluginRegistrant.h
13+
GeneratedPluginRegistrant.m
14+
15+
.generated/
16+
17+
*.pbxuser
18+
*.mode1v3
19+
*.mode2v3
20+
*.perspectivev3
21+
22+
!default.pbxuser
23+
!default.mode1v3
24+
!default.mode2v3
25+
!default.perspectivev3
26+
27+
xcuserdata
28+
29+
*.moved-aside
30+
31+
*.pyc
32+
*sync/
33+
Icon?
34+
.tags*
35+
36+
/Flutter/Generated.xcconfig
37+
/Flutter/ephemeral/
38+
/Flutter/flutter_export_environment.sh

ios/Assets/.gitkeep

Whitespace-only changes.

ios/Classes/ProtocolHandlerPlugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <Flutter/Flutter.h>
2+
3+
@interface ProtocolHandlerPlugin : NSObject<FlutterPlugin>
4+
@end

ios/Classes/ProtocolHandlerPlugin.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import "ProtocolHandlerPlugin.h"
2+
#if __has_include(<protocol_handler/protocol_handler-Swift.h>)
3+
#import <protocol_handler/protocol_handler-Swift.h>
4+
#else
5+
// Support project import fallback if the generated compatibility header
6+
// is not copied when this plugin is created as a library.
7+
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
8+
#import "protocol_handler-Swift.h"
9+
#endif
10+
11+
@implementation ProtocolHandlerPlugin
12+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
13+
[SwiftProtocolHandlerPlugin registerWithRegistrar:registrar];
14+
}
15+
@end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Flutter
2+
import UIKit
3+
4+
public class SwiftProtocolHandlerPlugin: NSObject, FlutterPlugin {
5+
private var channel: FlutterMethodChannel!
6+
7+
private var _initialUrl: String?
8+
9+
public static func register(with registrar: FlutterPluginRegistrar) {
10+
let channel = FlutterMethodChannel(name: "protocol_handler", binaryMessenger: registrar.messenger())
11+
let instance = SwiftProtocolHandlerPlugin()
12+
instance.channel = channel
13+
registrar.addMethodCallDelegate(instance, channel: channel)
14+
registrar.addApplicationDelegate(instance)
15+
}
16+
17+
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
18+
switch call.method {
19+
case "getInitialUrl":
20+
result(self._initialUrl ?? "");
21+
break;
22+
default:
23+
result(FlutterMethodNotImplemented)
24+
}
25+
}
26+
27+
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any] = [:]) -> Bool {
28+
let url: Any? = launchOptions[UIApplication.LaunchOptionsKey.url];
29+
if (url != nil) {
30+
self._initialUrl = (url as! URL).absoluteString
31+
}
32+
return true
33+
}
34+
35+
public func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
36+
let args: NSDictionary = [
37+
"url": url.absoluteString,
38+
]
39+
channel.invokeMethod("onProtocolUrlReceived", arguments: args, result: nil)
40+
return true
41+
}
42+
}

ios/protocol_handler.podspec

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
3+
# Run `pod lib lint protocol_handler.podspec` to validate before publishing.
4+
#
5+
Pod::Spec.new do |s|
6+
s.name = 'protocol_handler'
7+
s.version = '0.0.1'
8+
s.summary = 'A new flutter plugin project.'
9+
s.description = <<-DESC
10+
A new flutter plugin project.
11+
DESC
12+
s.homepage = 'http://example.com'
13+
s.license = { :file => '../LICENSE' }
14+
s.author = { 'Your Company' => '[email protected]' }
15+
s.source = { :path => '.' }
16+
s.source_files = 'Classes/**/*'
17+
s.dependency 'Flutter'
18+
s.platform = :ios, '9.0'
19+
20+
# Flutter.framework does not contain a i386 slice.
21+
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
22+
s.swift_version = '5.0'
23+
end

lib/src/protocol_registrar.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import 'dart:io';
22

3+
import 'protocol_registrar_impl_ios.dart';
34
import 'protocol_registrar_impl_macos.dart';
45
import 'protocol_registrar_impl_windows.dart';
56

67
class ProtocolRegistrar {
78
/// The shared instance of [ProtocolRegistrar].
89
static ProtocolRegistrar get instance {
10+
if (Platform.isIOS) return ProtocolRegistrarImplIOS.instance;
911
if (Platform.isMacOS) return ProtocolRegistrarImplMacOS.instance;
1012
if (Platform.isWindows) return ProtocolRegistrarImplWindows.instance;
1113
return ProtocolRegistrar();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'protocol_registrar.dart';
2+
3+
class ProtocolRegistrarImplIOS extends ProtocolRegistrar {
4+
ProtocolRegistrarImplIOS._();
5+
6+
/// The shared instance of [ProtocolRegistrarImplIOS].
7+
static final ProtocolRegistrarImplIOS instance = ProtocolRegistrarImplIOS._();
8+
9+
@override
10+
Future<void> register(String protocol) async {
11+
// Skip
12+
}
13+
}

0 commit comments

Comments
 (0)