SwiftUI适配iOS16导航控制器引起的闪退

news/2024/7/20 22:35:19 标签: swiftui, ios

当时iPhone14系列手机升级到iOS16.5.1系统以后,当用户登录后再次退出登录闪退货登录后退出登录闪退。
由于SwiftUI提倡用struct代替类,导致悲剧产生,闪退时无法打印是那个结构体(class类实现时会打印类名),因为是struct也没有deinit跟踪内存是否泄漏。开启僵尸进程打印只有一个这样的鬼话:

2023-06-30 19:52:42.637552+0800 xingqun_ios[4191:551916] *** -[_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext_ removeChildViewController:]: message sent to deallocated instance 0x10d02d000

定位闪退在main函数哪里。
iPhone14以下手机正常,只有iPhone14系列手机系统是iOS16才会出现。
经过三天个反复定位和查资料发现是iOS的导航栏变更产生的。iOS16要用NavigationStack代替NavigationView。

    var body: some View {
        if #available(iOS 16.0, *) {
            NavigationStack {
                VStack(spacing: 0) {
                    LoginTitleView(dismiss: .init(dismissAction: dismiss, type: .normal), from: .loginBySms) {
                        toPage = .toLoginPassword
                    }
                    phoneInput

                    // 新用户进入验证码注册页面 老用户进入验证码登录页面
                    switch loginModel.isNew {
                    case true: register
                    case false: loginByCode
                    default: Spacer()
                    }
                }
                .navigation(item: $toPage, destination: destination)
                .animation(.default, value: loginModel.isNew)
                .fullBackground(.white)
                .ignoresSafeArea(.keyboard, edges: .bottom)
            }
            .dismissKeyboard([.tap, .simulDrag])
            .noPaddingFullBackground(Color.white)
        } else {
            NavigationView {
                VStack(spacing: 0) {
                    LoginTitleView(dismiss: .init(dismissAction: dismiss, type: .normal), from: .loginBySms) {
                        toPage = .toLoginPassword
                    }
                    phoneInput

                    // 新用户进入验证码注册页面 老用户进入验证码登录页面
                    switch loginModel.isNew {
                    case true: register
                    case false: loginByCode
                    default: Spacer()
                    }
                }
                .navigation(item: $toPage, destination: destination)
                .animation(.default, value: loginModel.isNew)
                .fullBackground(.white)
                .ignoresSafeArea(.keyboard, edges: .bottom)
            }
            .dismissKeyboard([.tap, .simulDrag])
            .noPaddingFullBackground(Color.white)
        }
    }

闪退日志:


Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x0000001200000000
Exception Codes: 0x0000000000000002, 0x0000001200000000
VM Region Info: 0x1200000000 is in 0x1000000000-0x7000000000;  bytes after start: 8589934592  bytes before end: 403726925823
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      commpage (reserved)      fc0000000-1000000000 [  1.0G] ---/--- SM=NUL  ...(unallocated)
--->  GPU Carveout (reserved) 1000000000-7000000000 [384.0G] ---/--- SM=NUL  ...(unallocated)
      UNUSED SPACE AT END
Termination Reason: SIGNAL 10 Bus error: 10
Terminating Process: exc handler [638]

Triggered by Thread:  0

Thread 0 name:   Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib               	       0x1964fc414 lookUpImpOrForward + 64
1   libobjc.A.dylib               	       0x1964f6cc4 _objc_msgSend_uncached + 68
2   UIKitCore                     	       0x19f6ca538 -[UIViewController dealloc] + 772
3   UIKitCore                     	       0x19f6c8160 -[UINavigationController dealloc] + 308
4   UIKitCore                     	       0x19f95112c -[_UISplitViewControllerColumnContents .cxx_destruct] + 44
5   libobjc.A.dylib               	       0x1964f60a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
6   libobjc.A.dylib               	       0x1964fae00 objc_destructInstance + 80
7   libobjc.A.dylib               	       0x1965044fc _objc_rootDealloc + 80
8   CoreFoundation                	       0x19d48518c cow_cleanup + 168
9   CoreFoundation                	       0x19d4bd458 -[__NSDictionaryM dealloc] + 148
10  libobjc.A.dylib               	       0x1964f60a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
11  libobjc.A.dylib               	       0x1964fae00 objc_destructInstance + 80
12  libobjc.A.dylib               	       0x1965044fc _objc_rootDealloc + 80
13  libobjc.A.dylib               	       0x1964f60a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
14  libobjc.A.dylib               	       0x1964fae00 objc_destructInstance + 80
15  libobjc.A.dylib               	       0x1965044fc _objc_rootDealloc + 80
16  UIKitCore                     	       0x19f6ca96c -[UIResponder dealloc] + 124
17  UIKit                         	       0x2277b3f10 -[UIResponderAccessibility dealloc] + 56
18  UIKitCore                     	       0x19f6ca670 -[UIViewController dealloc] + 1084
19  libobjc.A.dylib               	       0x1964f61d4 AutoreleasePoolPage::releaseUntil(objc_object**) + 196
20  libobjc.A.dylib               	       0x1964f9bdc objc_autoreleasePoolPop + 256
21  UIKitCore                     	       0x19f66a44c -[_UIAfterCACommitBlock run] + 92
22  UIKitCore                     	       0x19f66a36c -[_UIAfterCACommitQueue flush] + 168
23  UIKitCore                     	       0x19f66a280 _runAfterCACommitDeferredBlocks + 496
24  UIKitCore                     	       0x19f508be8 _cleanUpAfterCAFlushAndRunDeferredBlocks + 108
25  UIKitCore                     	       0x19f9c7c18 _UIApplicationFlushCATransaction + 72
26  UIKitCore                     	       0x19fb184b0 _UIUpdateSequenceRun + 84
27  UIKitCore                     	       0x1a017cc8c schedulerStepScheduledMainSection + 144
28  UIKitCore                     	       0x1a017c1e8 runloopSourceCallback + 92
29  CoreFoundation                	       0x19d52e128 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
30  CoreFoundation                	       0x19d53a7b4 __CFRunLoopDoSource0 + 176
31  CoreFoundation                	       0x19d4bf5e8 __CFRunLoopDoSources0 + 244
32  CoreFoundation                	       0x19d4d50d4 __CFRunLoopRun + 828
33  CoreFoundation                	       0x19d4da3ec CFRunLoopRunSpecific + 612
34  GraphicsServices              	       0x1d897735c GSEventRunModal + 164
35  UIKitCore                     	       0x19f8676e8 -[UIApplication _run] + 888
36  UIKitCore                     	       0x19f86734c UIApplicationMain + 340

http://www.niftyadmin.cn/n/1007813.html

相关文章

HTML 编辑器的介绍及推荐

HTML 编辑器 HTML 编辑器是用于编写 HTML 的工具,使用 HTML 编辑器时以编辑主题,索引,自定义窗口,选择添加搜索页。 使用 Notepad 或 TextEdit 来编写 HTML 下列是三种专门用于编辑 HTML 的 HTML 编辑器: Adobe Dream…

python,[WinError 10049] 在其上下文中,该请求的地址无效

python 网络编程中,出现该错误: import socket skt socket.socket(familysocket.AF_INET, typesocket.SOCK_DGRAM) skt.bind((***, 5555))Traceback (most recent call last): File “***/test.py”, line 5, in skt.bind((’***’, 5555)) OSError: …

uniapp radio如何实现取消选中

uniapp 内置radio组件明确表示&#xff0c;不能取消选中&#xff0c;那如果要实现取消选中呢&#xff1f; 只要在外层加上label或者其他标签包裹&#xff0c;或者直接加入click事件然后加入事件控制radio的值改变即可 <label class"radio" click"changeAll&…

DL分布式训练基础之openmpi

文章目录 1. 安装openMPI2. mpirun基本命令3. mpirun单机多进程4. mpirun多机多进程5. mpi多机多进程的进程信息及端口等6. 测试openMPI的examples 1. 安装openMPI 这是一个后续分布式训练用到的一个调度框架&#xff0c;官网下载编译安装&#xff0c;这里使用较稳定的4.1.5&a…

gitlab---创建远程仓库方法

0 Preface/Foreword 前提是在gitlab服务器上创建了一个空白仓库&#xff08;有仓库地址&#xff0c;没有任何文件&#xff0c;readme.md文件也没有&#xff09;。 1 方法 通过command line方式创建远程仓库。 先设置账号名和邮箱&#xff0c;用于记录提交代码时显示作者信息…

【数据结构】——常见排序算法(演示图+代码+算法分析)

目录 1. 常见排序算法 1.2 稳定性 2. 常见排序算法的实现 2.1 插入排序 2.1.1基本思想 2.1.2代码 2.1.4算法分析 2.2 希尔排序 2.2.1基本思想 2.2.2代码 2.2.3演示图 2.2.4算法分析 2.3 选择排序 2.3.1基本思想 2.3.2代码 2.3.3演示图 2.3.4算法分析 2.4 堆排…

Quiz 16_3-1: Databases | Python for Everybody 配套练习_解题记录

文章目录 Python for Everybody课程简介Quiz 16_3-1: Databases单选题&#xff08;1-11&#xff09;操作题Autograder: Single Table SQL Python for Everybody 课程简介 Python for Everybody 零基础程序设计&#xff08;Python 入门&#xff09; This course aims to teach …

Tensorflow神经网络模型-鲜花种类识别

必应壁纸供图 Tensorflow神经网络模型-鲜花种类识别 数据集&#xff1a;https://download.csdn.net/download/weixin_53742691/87982215 导入相关依赖 import warnings import re from IPython.display import clear_output, display from tkinter import Tk, filedialog fro…