YwxMobileApp-iOS/Yiwangxin/PushNotificationHandler.swift
徐勤民 8b2796709b feat: YwxMobileApp-iOS 初始提交
三 Flavor(Shijiaobao / Clinical / Yiwangxin)iOS 项目

架构
- Shared/   全部共用层:AppHomeView、WebMessageHandler(JSBridge)、DevUrlSettings
- *Flavor/  各 flavor 入口:AppConfig、*App(@main)、AppDelegate(Yiwangxin 含 Push)
- project.yml + xcodegen 管理项目结构

SDK 集成
- 引用 Gitea SPM 包(branch: main,SNAPSHOT 开发模式)
- sdk.properties 追踪当前 SDK_REF,scripts/use-sdk.sh 支持 main/local/x.y.z 一键切换
- 含各 flavor xuqm/*.xuqmconfig 配置文件

JSBridge 协议
- window.webkit.messageHandlers.SZYX_APP.postMessage(json)
- 回调 window.SZYX_YWX_WebViewBridge.onMessage(json)
- 实现 setTitle/getDeviceInfo/login/setUserInfo/getAppVersion/checkUpdate
         setStorage/getStorage/removeStorage/clearStorage/setOrientation/apiError

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-29 11:29:49 +08:00

48 行
1.8 KiB
Swift

import UIKit
import XuqmCoreSDK
import XuqmWebViewSDK
import XuqmPushSDK
final class AppDelegate: NSObject, UIApplicationDelegate, PushMessageDelegate, @unchecked Sendable {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
PushSDK.shared.delegate = self
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
XuqmSDK.shared.registerDeviceToken(deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("[Push] Failed to register for remote notifications: \(error)")
}
// MARK: - PushMessageDelegate
func pushSDK(_ sdk: PushSDK, didReceiveMessage message: PushMessage) {
// Foreground notification: post to JS if WebView is active
if let payload = try? JSONSerialization.data(withJSONObject: message.payload),
let json = String(data: payload, encoding: .utf8) {
let js = "window.SZYX_YWX_WebViewBridge&&window.SZYX_YWX_WebViewBridge.onPushMessage(\(json))"
Task { @MainActor in
XWebViewBridge.shared.postMessageToWeb(js)
}
}
}
func pushSDK(_ sdk: PushSDK, didTapNotification message: PushMessage) {
// User tapped notification navigate to relevant page via JS bridge
if let payload = try? JSONSerialization.data(withJSONObject: message.payload),
let json = String(data: payload, encoding: .utf8) {
let js = "window.SZYX_YWX_WebViewBridge&&window.SZYX_YWX_WebViewBridge.onPushTapped(\(json))"
Task { @MainActor in
XWebViewBridge.shared.postMessageToWeb(js)
}
}
}
}