W2A流程梳理
This commit is contained in:
parent
d6e314a97f
commit
11cd8628aa
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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?
|
||||
|
Loading…
x
Reference in New Issue
Block a user