接入地图SDK
This commit is contained in:
@@ -1,13 +1,86 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
|
||||
///
|
||||
let kAMapKey = "key";
|
||||
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
) -> Bool {
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
|
||||
AMapNavSDKManager.shared().config(withKey: kAMapKey)
|
||||
|
||||
// 注册平台视图工厂
|
||||
let registrar = self.registrar(forPlugin: "NativeFirstPagePlugin")
|
||||
|
||||
let controller = window?.rootViewController as! FlutterViewController
|
||||
let nativeViewFactory = NativeViewFactory(messenger: controller.binaryMessenger)
|
||||
|
||||
registrar?.register(
|
||||
nativeViewFactory,
|
||||
withId: "NativeFirstPage"
|
||||
)
|
||||
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 创建视图工厂
|
||||
class NativeViewFactory: NSObject, FlutterPlatformViewFactory {
|
||||
private var messenger: FlutterBinaryMessenger
|
||||
|
||||
init(messenger: FlutterBinaryMessenger) {
|
||||
self.messenger = messenger
|
||||
super.init()
|
||||
}
|
||||
|
||||
func create(
|
||||
withFrame frame: CGRect,
|
||||
viewIdentifier viewId: Int64,
|
||||
arguments args: Any?
|
||||
) -> FlutterPlatformView {
|
||||
return NativeFlutterView(frame: frame, viewId: viewId, args: args)
|
||||
}
|
||||
|
||||
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
|
||||
return FlutterStandardMessageCodec.sharedInstance()
|
||||
}
|
||||
}
|
||||
|
||||
class NativeFlutterView: NSObject, FlutterPlatformView {
|
||||
private var _view: UIView
|
||||
private var _nativeVC: UIViewController
|
||||
|
||||
init(frame: CGRect, viewId: Int64, args: Any?) {
|
||||
// 创建原生的 ViewController 视图
|
||||
let nativeVC = AMapNavSDKManager.shared().targetVC;
|
||||
// let nativeVC = NativeFirstPage();
|
||||
|
||||
self._nativeVC = nativeVC
|
||||
|
||||
print("---frame: \(frame)");
|
||||
|
||||
_view = nativeVC.view
|
||||
_view.isUserInteractionEnabled = true
|
||||
_view.frame = CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))
|
||||
super.init()
|
||||
}
|
||||
|
||||
func view() -> UIView {
|
||||
return _view
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key></key>
|
||||
<string></string>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
@@ -16,6 +14,11 @@
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleLocalizations</key>
|
||||
<array>
|
||||
<string>zh-Hans</string>
|
||||
<string>en</string>
|
||||
</array>
|
||||
<key>CFBundleName</key>
|
||||
<string>ln_jq_app</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
@@ -28,6 +31,10 @@
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>iosamap</string>
|
||||
</array>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
@@ -44,6 +51,12 @@
|
||||
<string>需要访问您的相册以选择二维码图片进行识别</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>remote-notification</string>
|
||||
<string>fetch</string>
|
||||
<string>location</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
@@ -63,18 +76,5 @@
|
||||
</array>
|
||||
<key>uses</key>
|
||||
<string></string>
|
||||
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>remote-notification</string>
|
||||
<string>fetch</string>
|
||||
</array>
|
||||
|
||||
<key>CFBundleLocalizations</key>
|
||||
<array>
|
||||
<string>zh-Hans</string>
|
||||
<string>en</string>
|
||||
</array>
|
||||
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
66
ln_jq_app/ios/Runner/NativeFirstPage.swift
Normal file
66
ln_jq_app/ios/Runner/NativeFirstPage.swift
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// NativeFirstPage.swift
|
||||
// Runner
|
||||
//
|
||||
// Created by admin on 2026/2/9.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class NativeFirstPage: UIViewController {
|
||||
var lable:UILabel!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
view.backgroundColor = .white
|
||||
|
||||
// 创建原生UI
|
||||
let label = UILabel()
|
||||
label.text = "iOS 原生页面."
|
||||
label.font = UIFont.systemFont(ofSize: 24, weight: .bold)
|
||||
label.textAlignment = .center
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
let button = UIButton(type: .custom)
|
||||
button.setTitle("点击原生按钮", for: .normal)
|
||||
button.titleLabel?.font = UIFont.systemFont(ofSize: 18)
|
||||
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.backgroundColor = .blue
|
||||
|
||||
view.addSubview(label)
|
||||
view.addSubview(button)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
label.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -50),
|
||||
|
||||
button.topAnchor.constraint(equalTo: label.bottomAnchor, constant: 30),
|
||||
button.centerXAnchor.constraint(equalTo: view.centerXAnchor)
|
||||
])
|
||||
|
||||
self.lable = label
|
||||
|
||||
}
|
||||
|
||||
@objc func buttonTapped() {
|
||||
self.lable.text = "click...";
|
||||
|
||||
// 原生按钮点击事件
|
||||
let alert = UIAlertController(
|
||||
title: "原生弹窗",
|
||||
message: "来自 iOS 原生的提示",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
view.backgroundColor = .orange
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
#import <AMapNavSDKManager.h>
|
||||
|
||||
Reference in New Issue
Block a user