OGeek|极客世界-中国程序员成长平台

标题: ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:12
标题: ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会?

我正在构建一个新的 iOS 应用,在提交到 App Store 进行审核后,它被拒绝了,审核者说:

We discovered one or more bugs in your app when reviewed on iPad running iOS 12.3 on Wi-Fi.

Specifically, the app became stuck on the splash screen. No other content loaded.

但是,我个人无法重现此问题。

我已经尝试在所有带有 Xcode 的模拟器上进行干净安装,以及 iOS 12.3 上的物理 iPhone XS Max 和物理 iPad Pro 11 英寸。运行 iOS 12.3,并且该应用程序始终能够毫无问题地快速通过启动/启动屏幕。我所有的安装都是通过 Xcode 完成的,但我也尝试通过 TestFlight 进行安装,并且再次无法重现该问题。

编辑:应该提到我也尝试过没有网络连接并且应用程序加载成功。

代码

我只为启动屏幕使用 Storyboard,它只包含一个应用 Logo 的居中图像。除此之外,我所有的 UI 都是以编程方式完成的。在 AppDelegate didFinishLaunchingWithOptions 中,我安装了一个 Root View Controller ,它所做的第一件事是通过 Auth.auth().addStateDidChangeListener 检查 Firebase 身份验证。如果没有用户,那么我立即切换到登录 View Controller 。

由于第一次使用该应用程序的任何人都没有登录,我似乎无法理解为什么该应用程序会卡在初始屏幕上,除非 Firebase 身份验证监听器没有取得任何进展。

(已编辑以包含)下面的实际代码。

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    // Firebase
    FirebaseApp.configure()

    // Set custom root view controller
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = RootViewController()
    window?.makeKeyAndVisible()

    return true
}
class RootViewController: UIViewController {

    private var current: UIViewController

    init() {
        self.current = SplashViewController()
        super.init(nibName: nil, bundle: nil)
    }   

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        addChild(current)
        current.view.frame = view.bounds
        view.addSubview(current.view)
        current.didMove(toParent: self)
    }
    ...
}
class SplashViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white

        let image = UIImageView(image: UIImage(named: "1024.png")!)
        image.contentMode = .scaleAspectFit
        image.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(image)
        image.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        image.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        image.widthAnchor.constraint(equalToConstant: 128).isActive = true
        image.heightAnchor.constraint(equalToConstant: 128).isActive = true

        checkAuthenticationAndChangeScreens()
    }

    private func checkAuthenticationAndChangeScreens() {
        Auth.auth().addStateDidChangeListener { (auth, user) in
            if let user = user {
                UserDefaults.standard.set(user.uid, forKey: "userEmail")
                PushNotificationManager().registerForPushNotifications {
                    PartnerManager.shared.fetchPartnerEmail() {
                        AppDelegate.shared.rootViewController.switchToMainScreen()
                    }
                }
            } else {
                AppDelegate.shared.rootViewController.switchToLogOut()
                UIApplication.shared.unregisterForRemoteNotifications()
            }
        }
    }
}
// Class PushNotificationManager
func registerForPushNotifications(completion: @escaping () -> Void) {
    UNUserNotificationCenter.current().delegate = self
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
        granted, error in
        guard granted else { return }
        DispatchQueue.main.async {
            Messaging.messaging().delegate = self //Firebase Messaging
            UIApplication.shared.registerForRemoteNotifications()
            self.updateFirestorePushTokenIfNeeded() // Makes a single write to Firestore
            completion()
        }
    }
}
// Class PartnerManager
func fetchPartnerEmail(completion: @escaping () -> Void) {
    let userUID = UserDefaults.standard.string(forKey: "userEmail")
    db.collection("users").document(userUID).getDocument() {
        (document, error) in
        if let partnerEmail = document!.get("partnerEmail") as? String {
            UserDefaults.standard.set(partnerEmail, forKey: "partner")
        } 
        completion()
    }
}

有点奇怪

让我感到困惑的最后一件事是,虽然我向 App Store 提交的申请被拒绝了,理由是应用程序卡在了启动屏幕上(以及启动屏幕的屏幕截图),但我提交的 Beta 测试构建是由于不同的原因被拒绝 - 我没有提供我应该提供的登录详细信息,但在这里他们提供了我登录屏幕的屏幕截图。但这意味着该应用程序已经超越了 Beta 测试审查的初始屏幕。

这让我想到问题可能出在 Apple 的某种测试环境上。

Apple 审查测试环境有什么不同吗?我怎样才能更好地尝试重现这个卡住的闪屏问题?为什么 Beta 测试审阅者似乎能够正确加载应用,而 App Store 审阅者却不能?



Best Answer-推荐答案


这可能是因为您的 UI 更新没有在主线程上完成。

试试:

DispatchQueue.main.async {
    //Update rootViewController now
}

我曾经犯过类似的错误。 这是一个随机问题,因为 UI 更新不能保证,因为它没有在主线程上明确显示。

关于ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56141225/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4