当前位置: 首页 > news >正文

ios调用高德地图定位报错

错误信息如下:

Thread Performance Checker: Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. Investigate ways to avoid priority inversions

PID: 1668, TID: 15380

Backtrace

=================================================================

3   Foundation                          0x0000000113be3985 -[_NSThreadPerformInfo wait] + 64

4   Foundation                          0x0000000113be5da5 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 907

5   yydj                                0x0000000100fa1e89 -[AMapLocationManager startUpdatingLocation] + 98

6   yydj                                0x0000000100f15a68 $s4yydj14ViewControllerC8locationyyF + 408

7   yydj                                0x0000000100f1557b $s4yydj14ViewControllerC11viewDidLoadyyF + 1675

8   yydj                                0x0000000100f158bc $s4yydj14ViewControllerC11viewDidLoadyyFTo + 28

9   UIKitCore                           0x000000012a7bafee -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 80

10  UIKitCore                           0x000000012a7c10e6 -[UIViewController loadViewIfRequired] + 1342

11  UIKitCore                           0x000000012a6dcb2b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 159

12  UIKitCore                           0x000000012a6dce5f -[UINavigationController _startTransition:fromViewController:toViewController:] + 210

13  UIKitCore                           0x000000012a6de035 -[UINavigationController _startDeferredTransitionIfNeeded:] + 856

14  UIKitCore                           0x000000012a6df495 -[UINavigationController __viewWillLayoutSubviews] + 136

15  UIKitCore                           0x000000012a6bbde2 -[UILayoutContainerView layoutSubviews] + 207

16  UIKit                               0x0000000150bf9c73 -[UILayoutContainerViewAccessibility layoutSubviews] + 51

17  UIKitCore                           0x000000012b88af3c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2138

18  QuartzCore                          0x000000010e313775 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 527

19  QuartzCore                          0x000000010e31f5a1 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 67

20  QuartzCore                          0x000000010e23ecf4 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 706

21  QuartzCore                          0x000000010e27982a _ZN2CA11Transaction6commitEv + 728

22  UIKitCore                           0x000000012b1c9d8f __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 34

23  CoreFoundation                      0x000000010f4f5dea __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12

24  CoreFoundation                      0x000000010f4f559d __CFRunLoopDoBlocks + 391

25  CoreFoundation                      0x000000010f4efe7c __CFRunLoopRun + 940

26  CoreFoundation                      0x000000010f4ef6ed CFRunLoopRunSpecific + 557

27  GraphicsServices                    0x000000011c76f08f GSEventRunModal + 137

28  UIKitCore                           0x000000012b1aa6ee -[UIApplication _run] + 972

29  UIKitCore                           0x000000012b1af16e UIApplicationMain + 123

30  UIKitCore                           0x000000012a22ab73 __swift_destroy_boxed_opaque_existential_1Tm + 10307

31  yydj                                0x0000000100f20f5b $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 123

32  yydj                                0x0000000100f20ed7 $s4yydj11AppDelegateC5$mainyyFZ + 39

33  yydj                                0x0000000100f21008 main + 24

Message from debugger: killed

回答:

这个错误信息表明你的应用在执行用户交互质量的服务时,阻塞在了一个较低优先级的线程上,这导致了优先级倒置。特别是,你的应用在调用`AMapLocationManager`的`startUpdatingLocation`时发生了这个问题。这可能会导致应用性能问题。以下是一些可能的解决方法:

### 1. 在后台线程中启动位置更新

`AMapLocationManager`的`startUpdatingLocation`可能是一个耗时操作,应该在后台线程中运行,而不是在主线程中。你可以使用`DispatchQueue`来处理:

```swift
DispatchQueue.global(qos: .background).async {
    self.locationManager.startUpdatingLocation()
}
```

### 2. 确保UI更新在主线程中进行

所有的UI更新都应该在主线程中进行。确保你所有涉及UI更新的代码都在主线程中运行:

```swift
DispatchQueue.main.async {
    // 更新UI
}
```

### 3. 优化`viewDidLoad`方法

确保`viewDidLoad`方法中没有长时间运行的任务。如果有,将这些任务移到后台线程中执行:

```swift
override func viewDidLoad() {
    super.viewDidLoad()
    
    DispatchQueue.global(qos: .background).async {
        self.locationManager.startUpdatingLocation()
    }
    
    // 其他初始化代码
}
```

### 4. 检查线程优先级

确保线程优先级设置正确。可以使用`qos`(质量服务类)来设置线程优先级:

```swift
DispatchQueue.global(qos: .userInitiated).async {
    // 用户交互相关的任务
}

DispatchQueue.global(qos: .background).async {
    // 后台任务
}
```

### 5. 避免死锁

确保你没有在主线程中执行可能会导致死锁的操作,例如同步调用`DispatchQueue`,特别是在涉及到UI更新和网络请求时。

### 6. 其他性能优化

- 优化`viewDidLoad`方法,确保只做必要的初始化工作。
- 使用`Instruments`工具分析性能瓶颈,特别是线程的优先级和阻塞情况。
- 评估是否有不必要的阻塞调用,重构代码以避免长时间占用主线程。

### 代码示例

```swift
import UIKit
import AMapLocationKit

class ViewController: UIViewController {
    var locationManager: AMapLocationManager!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 初始化位置管理器
        locationManager = AMapLocationManager()
        
        // 在后台线程中启动位置更新
        DispatchQueue.global(qos: .background).async {
            self.locationManager.startUpdatingLocation()
        }
        
        // 其他初始化代码
    }
}
```

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • (八)Flink Join 连接
  • shaushaushau1
  • matlab实现模拟退火算法
  • 软考-软件设计师(程序设计语言习题)
  • 苹果上架没有iphone、没有ipad也可以生成截屏
  • python编程练习1-数组
  • 【内网】服务器升级nginx1.17.0
  • HarmonyOS 地图服务:深度解析其丰富功能与精准导航实力
  • TCP和UDP编程的学习
  • 【python】灰色预测 GM(1,1) 模型
  • Coze插件发布!PDF转Markdown功能便捷集成,打造你的专属智能体
  • 使用PCF8591实现一个串口控制电压表
  • 第三期书生大模型实战营 进阶岛第3关LMDeploy 量化部署进阶实践
  • Eclipse的使用配置教程:必要设置、创建工程及可能遇到的问题(很详细,很全面,能解决90%的问题)
  • 开发小运维-jar包服务shell启动脚本
  • 08.Android之View事件问题
  • docker容器内的网络抓包
  • ES2017异步函数现已正式可用
  • Git学习与使用心得(1)—— 初始化
  • JS数组方法汇总
  • nginx 负载服务器优化
  • Otto开发初探——微服务依赖管理新利器
  • Python进阶细节
  • Python利用正则抓取网页内容保存到本地
  • Redis 中的布隆过滤器
  • 如何使用Mybatis第三方插件--PageHelper实现分页操作
  • 使用putty远程连接linux
  • 线上 python http server profile 实践
  • gunicorn工作原理
  • Nginx惊现漏洞 百万网站面临“拖库”风险
  • ​LeetCode解法汇总1276. 不浪费原料的汉堡制作方案
  • #单片机(TB6600驱动42步进电机)
  • (¥1011)-(一千零一拾一元整)输出
  • (4)(4.6) Triducer
  • (51单片机)第五章-A/D和D/A工作原理-A/D
  • (solr系列:一)使用tomcat部署solr服务
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (每日一问)操作系统:常见的 Linux 指令详解
  • (一)基于IDEA的JAVA基础12
  • (原創) 博客園正式支援VHDL語法著色功能 (SOC) (VHDL)
  • (转)GCC在C语言中内嵌汇编 asm __volatile__
  • (转)JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
  • (转载)PyTorch代码规范最佳实践和样式指南
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)
  • **PHP分步表单提交思路(分页表单提交)
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • .NET CORE 第一节 创建基本的 asp.net core
  • .net framework 4.8 开发windows系统服务
  • .NET Framework 服务实现监控可观测性最佳实践
  • .NET 除了用 Task 之外,如何自己写一个可以 await 的对象?
  • .NET程序集编辑器/调试器 dnSpy 使用介绍
  • .NET中的Exception处理(C#)
  • :如何用SQL脚本保存存储过程返回的结果集
  • @font-face 用字体画图标