接入微信分享 SDK 并配置 Universal Link。
集成 WechatOpenSDK、www.zhifly.cn/suixinkan/ 通用链接与邀请页分享能力,附带 AASA 部署文件与单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -7,8 +7,38 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
/// AppDelegate 承接 APNs 系统回调,SwiftUI App 入口通过 adaptor 注入。
|
||||
/// AppDelegate 承接 APNs 与微信 SDK 系统回调,SwiftUI App 入口通过 adaptor 注入。
|
||||
final class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
||||
) -> Bool {
|
||||
Task { @MainActor in
|
||||
WeChatManager.shared.registerIfNeeded()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func application(
|
||||
_ app: UIApplication,
|
||||
open url: URL,
|
||||
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
|
||||
) -> Bool {
|
||||
MainActor.assumeIsolated {
|
||||
WeChatManager.shared.handleOpenURL(url)
|
||||
}
|
||||
}
|
||||
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
continue userActivity: NSUserActivity,
|
||||
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
|
||||
) -> Bool {
|
||||
MainActor.assumeIsolated {
|
||||
WeChatManager.shared.handleContinueUserActivity(userActivity)
|
||||
}
|
||||
}
|
||||
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
|
||||
|
||||
36
suixinkan/App/WeChatConfig.swift
Normal file
36
suixinkan/App/WeChatConfig.swift
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// WeChatConfig.swift
|
||||
// suixinkan
|
||||
//
|
||||
// 微信 Open SDK 配置。上线前请替换为开放平台真实 AppID,并同步 Info.plist URL Scheme。
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 微信开放平台接入配置,集中管理 AppID 与 Universal Link。
|
||||
enum WeChatConfig {
|
||||
/// 占位 AppID,上线前替换为微信开放平台移动应用 AppID。
|
||||
static let appID = "wxdd80ec12c4fee322"
|
||||
|
||||
/// Universal Link,必须以 `/` 结尾,且与开放平台填写完全一致。
|
||||
static let universalLink = "https://www.zhifly.cn/suixinkan/"
|
||||
|
||||
/// Associated Domains 域名(不含 `applinks:` 前缀)。
|
||||
static let associatedDomain = "www.zhifly.cn"
|
||||
|
||||
/// AASA 文件 paths 通配规则,需与运维部署的 apple-app-site-association 一致。
|
||||
static let aasaPathPattern = "/suixinkan/*"
|
||||
|
||||
/// Apple Team ID + Bundle ID,供运维部署 AASA 使用。
|
||||
static let aasaAppID = "56GVN5RNVN.com.yuanzhixiang.suixinkan"
|
||||
|
||||
/// 校验 Universal Link 格式是否符合微信要求。
|
||||
static func validateUniversalLink(_ link: String) -> Bool {
|
||||
guard let url = URL(string: link),
|
||||
url.scheme?.lowercased() == "https",
|
||||
link.hasSuffix("/") else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,12 @@ struct suixinkanApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
RootView()
|
||||
.onOpenURL { url in
|
||||
WeChatManager.shared.handleOpenURL(url)
|
||||
}
|
||||
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in
|
||||
_ = WeChatManager.shared.handleContinueUserActivity(userActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user