菜鸟教程小白 发表于 2022-12-12 15:12:06

ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会?


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

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

<p>Specifically, the app became stuck on the splash screen. No other content loaded.</p>
</blockquote>

<p>但是,我个人无法重现此问题。 </p>

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

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

<h2>代码</h2>

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

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

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

<pre class="lang-swift prettyprint-override"><code>func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: ?) -&gt; 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
}
</code></pre>

<pre class="lang-swift prettyprint-override"><code>class RootViewController: UIViewController {

    private var current: UIViewController

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

    required init?(coder aDecoder: NSCoder) {
      fatalError(&#34;init(coder:) has not been implemented&#34;)
    }

    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)
    }
    ...
}
</code></pre>

<pre class="lang-swift prettyprint-override"><code>class SplashViewController: UIViewController {

    override func viewDidLoad() {
      super.viewDidLoad()

      view.backgroundColor = UIColor.white

      let image = UIImageView(image: UIImage(named: &#34;1024.png&#34;)!)
      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: &#34;userEmail&#34;)
                PushNotificationManager().registerForPushNotifications {
                  PartnerManager.shared.fetchPartnerEmail() {
                        AppDelegate.shared.rootViewController.switchToMainScreen()
                  }
                }
            } else {
                AppDelegate.shared.rootViewController.switchToLogOut()
                UIApplication.shared.unregisterForRemoteNotifications()
            }
      }
    }
}
</code></pre>

<pre class="lang-swift prettyprint-override"><code>// Class PushNotificationManager
func registerForPushNotifications(completion: @escaping () -&gt; 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()
      }
    }
}
</code></pre>

<pre class="lang-swift prettyprint-override"><code>// Class PartnerManager
func fetchPartnerEmail(completion: @escaping () -&gt; Void) {
    let userUID = UserDefaults.standard.string(forKey: &#34;userEmail&#34;)
    db.collection(&#34;users&#34;).document(userUID).getDocument() {
      (document, error) in
      if let partnerEmail = document!.get(&#34;partnerEmail&#34;) as? String {
            UserDefaults.standard.set(partnerEmail, forKey: &#34;partner&#34;)
      }
      completion()
    }
}
</code></pre>

<h2>有点奇怪</h2>

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

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

<p>Apple 审查测试环境有什么不同吗?我怎样才能更好地尝试重现这个卡住的闪屏问题?为什么 Beta 测试审阅者似乎能够正确加载应用,而 App Store 审阅者却不能?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这可能是因为您的 UI 更新没有在主线程上完成。</p>

<p>试试:</p>

<pre><code>DispatchQueue.main.async {
    //Update rootViewController now
}
</code></pre>

<p>我曾经犯过类似的错误。
这是一个随机问题,因为 UI 更新不能保证,因为它没有在主线程上明确显示。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/56141225/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/56141225/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 为什么我的 iOS 应用程序可能会卡在 Apple 评论者的闪屏上,而我却不会?