Skip to content

Commit f7f9f1b

Browse files
committed
Add ios supported
1 parent 4698978 commit f7f9f1b

14 files changed

+211
-46
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ build/
3232
.metadata
3333
*.g.dart
3434
Pigeon.java
35+
Pigeon.h
36+
Pigeon.m

example/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ app.*.map.json
4848

4949
android/
5050
ios/
51+
linux/
52+
macos/
53+
windows/
54+
web/

example/lib/main.dart

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class App extends StatelessWidget {
1414
home: Scaffold(
1515
appBar: AppBar(title: const Text('腾讯地图')),
1616
body: TencentMap(
17+
rotateGesturesEnabled: false,
18+
tiltGesturesEnabled: false,
1719
onMapCreated: (container) {},
1820
),
1921
),

ios/.gitignore

+38
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.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Flutter
2+
3+
public class SwiftTencentMapPlugin: NSObject, FlutterPlugin {
4+
public static func register(with registrar: FlutterPluginRegistrar) {
5+
registrar.register(TencentMapFactory(registrar: registrar), withId: "tencent_map")
6+
TencentMapSdkApiSetup(registrar.messenger(), _TencentMapSdkApi())
7+
}
8+
}

ios/Classes/TencentMap.swift

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Flutter
2+
import QMapKit
3+
4+
class TencentMapFactory: NSObject, FlutterPlatformViewFactory {
5+
let registrar: FlutterPluginRegistrar
6+
7+
init(registrar: FlutterPluginRegistrar) {
8+
self.registrar = registrar
9+
}
10+
11+
func create(withFrame _: CGRect, viewIdentifier _: Int64, arguments _: Any?) -> FlutterPlatformView {
12+
MapView(registrar)
13+
}
14+
}
15+
16+
class MapView: NSObject, FlutterPlatformView, QMapViewDelegate {
17+
let mapView: QMapView
18+
let api: _TencentMapApi
19+
20+
init(_ registrar: FlutterPluginRegistrar) {
21+
mapView = QMapView()
22+
api = _TencentMapApi(mapView)
23+
TencentMapApiSetup(registrar.messenger(), api)
24+
super.init()
25+
mapView.delegate = self
26+
}
27+
28+
func view() -> UIView {
29+
mapView
30+
}
31+
}

ios/Classes/TencentMapApi.swift

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import QMapKit
2+
3+
class _TencentMapApi: NSObject, TencentMapApi {
4+
let mapView: QMapView
5+
6+
init(_ mapView: QMapView) {
7+
self.mapView = mapView
8+
}
9+
10+
func setMapTypeType(_ type: MapType, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
11+
mapView.mapType = [
12+
MapType.dark: QMapType.dark,
13+
MapType.normal: QMapType.standard,
14+
MapType.satellite: QMapType.satellite,
15+
][type] ?? QMapType.standard
16+
}
17+
18+
func setCompassEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
19+
mapView.showsCompass = enabled.boolValue
20+
}
21+
22+
func setScaleControlsEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
23+
mapView.showsScale = enabled.boolValue
24+
}
25+
26+
func setRotateGesturesEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
27+
mapView.isRotateEnabled = enabled.boolValue
28+
}
29+
30+
func setScrollGesturesEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
31+
mapView.isScrollEnabled = enabled.boolValue
32+
}
33+
34+
func setZoomGesturesEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
35+
mapView.isZoomEnabled = enabled.boolValue
36+
}
37+
38+
func setTiltGesturesEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
39+
mapView.isOverlookingEnabled = enabled.boolValue
40+
}
41+
42+
func setIndoorViewEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
43+
mapView.setIndoorEnabled(enabled.boolValue)
44+
}
45+
46+
func setTrafficEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
47+
mapView.showsTraffic = enabled.boolValue
48+
}
49+
50+
func setBuildingsEnabledEnabled(_ enabled: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
51+
mapView.showsBuildings = enabled.boolValue
52+
}
53+
54+
func moveCameraPosition(_: [AnyHashable: Any], duration _: NSNumber, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {}
55+
56+
func pauseWithError(_: AutoreleasingUnsafeMutablePointer<FlutterError?>) {}
57+
58+
func resumeWithError(_: AutoreleasingUnsafeMutablePointer<FlutterError?>) {}
59+
60+
func startWithError(_: AutoreleasingUnsafeMutablePointer<FlutterError?>) {}
61+
62+
func stopWithError(_: AutoreleasingUnsafeMutablePointer<FlutterError?>) {}
63+
}

ios/Classes/TencentMapPlugin.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <Flutter/Flutter.h>
2+
3+
@interface TencentMapPlugin : NSObject<FlutterPlugin>
4+
@end

ios/Classes/TencentMapPlugin.m

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#import "TencentMapPlugin.h"
2+
#if __has_include(<tencent_map/tencent_map-Swift.h>)
3+
#import <tencent_map/tencent_map-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 "tencent_map-Swift.h"
9+
#endif
10+
11+
@implementation TencentMapPlugin
12+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
13+
[SwiftTencentMapPlugin registerWithRegistrar:registrar];
14+
}
15+
@end

ios/Classes/TencentMapSdkApi.swift

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import QMapKit
2+
3+
class _TencentMapSdkApi: NSObject, TencentMapSdkApi {
4+
func initSdkIosApiKey(_ iosApiKey: String, error _: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
5+
QMapServices.shared().apiKey = iosApiKey
6+
QMapServices.shared().setPrivacyAgreement(true)
7+
}
8+
}

ios/tencent_map.podspec

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
3+
# Run `pod lib lint tencent_map.podspec` to validate before publishing.
4+
#
5+
Pod::Spec.new do |s|
6+
s.name = 'tencent_map'
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+
24+
s.dependency 'Tencent-MapSDK', '~> 4.5.7'
25+
s.static_framework = true
26+
end

lib/src/pigeon.dart

+8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
// ignore: depend_on_referenced_packages
12
import 'package:pigeon/pigeon.dart';
23

34
@ConfigurePigeon(
45
PigeonOptions(
56
dartOut: 'lib/src/pigeon.g.dart',
67
javaOut: 'android/src/main/java/qiuxiang/tencent_map/Pigeon.java',
78
javaOptions: JavaOptions(package: 'qiuxiang.tencent_map'),
9+
objcHeaderOut: 'ios/Classes/Pigeon.h',
10+
objcSourceOut: 'ios/Classes/Pigeon.m',
811
),
912
)
13+
@HostApi()
14+
abstract class TencentMapSdkApi {
15+
void initSdk(String iosApiKey);
16+
}
17+
1018
@HostApi()
1119
abstract class TencentMapApi {
1220
void setMapType(MapType type);

pubspec.yaml

+2-46
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,18 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
plugin_platform_interface: ^2.0.2
1413

1514
dev_dependencies:
1615
flutter_test:
1716
sdk: flutter
1817
flutter_lints: ^2.0.0
1918
pigeon: ^3.1.3
2019

21-
# For information on the generic Dart part of this file, see the
22-
# following page: https://dart.dev/tools/pub/pubspec
23-
24-
# The following section is specific to Flutter packages.
2520
flutter:
26-
# This section identifies this Flutter project as a plugin project.
27-
# The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.)
28-
# which should be registered in the plugin registry. This is required for
29-
# using method channels.
30-
# The Android 'package' specifies package in which the registered class is.
31-
# This is required for using method channels on Android.
32-
# The 'ffiPlugin' specifies that native code should be built and bundled.
33-
# This is required for using `dart:ffi`.
34-
# All these are used by the tooling to maintain consistency when
35-
# adding or updating assets for this project.
3621
plugin:
3722
platforms:
3823
android:
3924
package: qiuxiang.tencent_map
4025
pluginClass: TencentMapPlugin
41-
42-
# To add assets to your plugin package, add an assets section, like this:
43-
# assets:
44-
# - images/a_dot_burr.jpeg
45-
# - images/a_dot_ham.jpeg
46-
#
47-
# For details regarding assets in packages, see
48-
# https://flutter.dev/assets-and-images/#from-packages
49-
#
50-
# An image asset can refer to one or more resolution-specific "variants", see
51-
# https://flutter.dev/assets-and-images/#resolution-aware
52-
53-
# To add custom fonts to your plugin package, add a fonts section here,
54-
# in this "flutter" section. Each entry in this list should have a
55-
# "family" key with the font family name, and a "fonts" key with a
56-
# list giving the asset and other descriptors for the font. For
57-
# example:
58-
# fonts:
59-
# - family: Schyler
60-
# fonts:
61-
# - asset: fonts/Schyler-Regular.ttf
62-
# - asset: fonts/Schyler-Italic.ttf
63-
# style: italic
64-
# - family: Trajan Pro
65-
# fonts:
66-
# - asset: fonts/TrajanPro.ttf
67-
# - asset: fonts/TrajanPro_Bold.ttf
68-
# weight: 700
69-
#
70-
# For details regarding fonts in packages, see
71-
# https://flutter.dev/custom-fonts/#from-packages
26+
ios:
27+
pluginClass: TencentMapPlugin

0 commit comments

Comments
 (0)