W2A流程梳理

This commit is contained in:
zeng 2025-06-17 09:40:35 +08:00
parent d6e314a97f
commit 11cd8628aa
6 changed files with 64 additions and 17 deletions

View File

@ -10,6 +10,8 @@ import FirebaseMessaging
import FirebaseCore
extension AppDelegate {
///
static var haveBeenShownAPNS = false
func registerAPNS() {
FirebaseApp.configure()
@ -20,8 +22,8 @@ extension AppDelegate {
center.requestAuthorization(options: [.badge, .sound, .alert]) { grant, error in
if !grant {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if let date = UserDefaults.standard.object(forKey: kSPApnsAlertDefaultsKey) as? Date {
if let date = UserDefaults.standard.object(forKey: kSPApnsAlertDefaultsKey) as? Date {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
#if DEBUG
self.showApnsAlert()
#else
@ -30,8 +32,15 @@ extension AppDelegate {
}
#endif
}
UserDefaults.standard.set(Date(), forKey: kSPApnsAlertDefaultsKey)
} else {
Self.haveBeenShownAPNS = true
SPAPPTool.sceneDelegate?.retryHandleOpenAppMessage()
}
UserDefaults.standard.set(Date(), forKey: kSPApnsAlertDefaultsKey)
} else {
Self.haveBeenShownAPNS = true
SPAPPTool.sceneDelegate?.retryHandleOpenAppMessage()
}
}
UIApplication.shared.registerForRemoteNotifications()

View File

@ -18,11 +18,14 @@ extension SceneDelegate {
guard let url = URLContexts.first?.url else {
return
}
var result = false
#if canImport(FacebookCore)
ApplicationDelegate.shared.application(UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation])
result = ApplicationDelegate.shared.application(UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation])
#endif
if !result {
handleOpenAppMessage(webpageURL: url)
}
}
@ -38,16 +41,44 @@ extension SceneDelegate {
extension SceneDelegate {
static var hasOpenMessage = false
///
static var isNeedRetry = false
private static var webpageURL: URL?
func handleOpenAppMessage(webpageURL: URL?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
guard SPNetworkReachabilityManager.manager.isReachable == true, AppDelegate.haveBeenShownAPNS, SPAPPTool.isAppOpen else {
if let webpageURL = webpageURL {
SceneDelegate.webpageURL = webpageURL
}
Self.isNeedRetry = true
return
}
Self.isNeedRetry = false
SceneDelegate.webpageURL = nil
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self._handleOpenAppMessage(webpageURL: webpageURL)
}
}
///
func retryHandleOpenAppMessage() {
guard Self.isNeedRetry else { return }
handleOpenAppMessage(webpageURL: SceneDelegate.webpageURL)
}
private func _handleOpenAppMessage(webpageURL: URL?) {
if !SPAPPTool.isAppOpen { return }
if Self.hasOpenMessage { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
Self.hasOpenMessage = false
}
Self.hasOpenMessage = true
//URL
var statUrlStr: String?
var data: [String : Any]?
@ -63,14 +94,7 @@ extension SceneDelegate {
statUrlStr = pasteStr
}
}
if Self.hasOpenMessage {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
Self.hasOpenMessage = false
}
Self.hasOpenMessage = true
if data == nil {

View File

@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SPAPPTool.appDelegate = self
self.registThirdparty(application, didFinishLaunchingWithOptions: launchOptions)

View File

@ -15,7 +15,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
SPAPPTool.sceneDelegate = self
SPAPPTool.windowScene = windowScene
///
@ -25,6 +25,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
///
// NotificationCenter.default.addObserver(self, selector: #selector(loginStateDidChangeNotification), name: SPLoginManager.loginStateDidChangeNotification, object: nil)
if let webpageURL = connectionOptions.userActivities.first?.webpageURL {
self.handleOpenAppMessage(webpageURL: webpageURL)
}
window = UIWindow(windowScene: windowScene)
@ -60,7 +63,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
handleOpenAppMessage(webpageURL: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.handleOpenAppMessage(webpageURL: nil)
}
}
func sceneDidEnterBackground(_ scene: UIScene) {
@ -131,7 +137,7 @@ extension SceneDelegate {
@objc private func handleOpenApp() {
setTabBarController()
handleOpenAppMessage(webpageURL: nil)
retryHandleOpenAppMessage()
}
@ -147,6 +153,8 @@ extension SceneDelegate {
///
@objc private func reachabilityDidChangeNotification() {
retryHandleOpenAppMessage()
let localizedData = SPLocalizedManager.shared.localizedData ?? [:]
if SPNetworkReachabilityManager.manager.isReachable == true {

View File

@ -90,9 +90,12 @@ class SPApnsAlertView: UIView {
@objc private func handleLaterButton() {
self.removeFromSuperview()
AppDelegate.haveBeenShownAPNS = true
SPAPPTool.sceneDelegate?.retryHandleOpenAppMessage()
}
@objc private func handleAllowButton() {
AppDelegate.haveBeenShownAPNS = true
self.removeFromSuperview()
SPAPPTool.openApnsSetting()
}

View File

@ -12,6 +12,9 @@ class SPAPPTool: NSObject {
///app
static var isAppOpen = true
static var appDelegate: AppDelegate?
static var sceneDelegate: SceneDelegate?
static var windowScene: UIWindowScene?
static var mainTabBarController: SPTabBarController?