AppDelegate.swift
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import UIKit
import Flutter
// Add these two import lines
import TIMPush
import tencent_cloud_chat_push
@main
@objc class AppDelegate: FlutterAppDelegate,TIMPushDelegate {
private var edgePanRecognizer: UIScreenEdgePanGestureRecognizer?
private var methodChannel: FlutterMethodChannel?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// 获取 root FlutterViewController 实例
guard let controller = window?.rootViewController as? FlutterViewController else {
fatalError("rootViewController is not a FlutterViewController")
}
// 注册插件
GeneratedPluginRegistrant.register(with: self)
// 创建 MethodChannel,用于与 Flutter 通信
methodChannel = FlutterMethodChannel(
name: "ios_edge_swipe",
binaryMessenger: controller.binaryMessenger
)
methodChannel?.setMethodCallHandler { [weak self] (call, result) in
if call.method == "initSwipeListener" {
self?.setupEdgeSwipeGesture(controller: controller)
result(nil)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// 添加边缘滑动手势识别器
private func setupEdgeSwipeGesture(controller: UIViewController) {
if edgePanRecognizer != nil {
return // 防止重复添加
}
edgePanRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(handleEdgeSwipe(_:)))
edgePanRecognizer?.edges = [.left] // 监听左边缘
edgePanRecognizer?.delegate = self
controller.view.addGestureRecognizer(edgePanRecognizer!)
print("✅ 左边缘滑动手势监听已添加")
}
// 触发时回调
@objc private func handleEdgeSwipe(_ gesture: UIScreenEdgePanGestureRecognizer) {
if gesture.state == .recognized {
methodChannel?.invokeMethod("onEdgeSwipe", arguments: nil)
print("👈 左边缘滑动检测到!已通知 Flutter")
}
}
// To be deprecated,please use the new field businessID below.
@objc func offlinePushCertificateID() -> Int32 {
return TencentCloudChatPushFlutterModal.shared.offlinePushCertificateID();
}
// Add this function
@objc func businessID() -> Int32 {
return TencentCloudChatPushFlutterModal.shared.businessID();
}
// Add this function
@objc func applicationGroupID() -> String {
return TencentCloudChatPushFlutterModal.shared.applicationGroupID()
}
// Add this function
@objc func onRemoteNotificationReceived(_ notice: String?) -> Bool {
TencentCloudChatPushPlugin.shared.tryNotifyDartOnNotificationClickEvent(notice)
return true
}
}
// 可选:防止冲突的手势识别设置
extension AppDelegate: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// 如果需要同时识别,比如与 WebView 的滚动手势共存
return true
}
}