gpt4 book ai didi

ios - 崩溃:libsystem_pthread.dylib:_pthread_wqthread

转载 作者:行者123 更新时间:2023-11-30 12:25:39 24 4
gpt4 key购买 nike

这是我的应用程序在 AppStore 中发生的第 1 次崩溃。问题是我找不到解决这个问题的方法,因为我无法重现它,也不知道是什么原因造成的。崩溃日志内容如下:

线程 0.8 是 didUpdateLocations

First Thread Last 2 Thread

我认为它可能在 checkStealRange() 中,但我没有发现其中有什么问题。

func checkStealRange() {

var objectsWithdistance = [PFObject]()
stealobject = nil
print("checkin steal and setting stealobject to nil")

if nearbystreets.count != 0 {
for object in self.nearbystreets {
if let lon = object["lon"] as? Double, let lat = object["lat"] as? Double{
let locationStreet = CLLocation(latitude: lat, longitude: lon)
if let currentLocation = self.locationManager.location {
let distance = currentLocation.distance(from: locationStreet)
object["distance"] = distance
objectsWithdistance.append(object)
} else {
if self.lastlocationregionset != nil {
let distance = self.lastlocationregionset!.distance(from: locationStreet)
object["distance"] = distance
objectsWithdistance.append(object)
}
}
}
}
} else {
print("no nearby streets loaded to check for steal")
stealButton.isEnabled = false
return
}

if objectsWithdistance.count > 0 {
print("objectsWithdistance count:", objectsWithdistance.count)
let sortedArray = (objectsWithdistance as NSArray).sortedArray(using: [
NSSortDescriptor(key: "distance", ascending: true)
])
for object in sortedArray {
guard let street = object as? PFObject else { continue }
if let streetDistance = street["distance"] as? Double {
var allowedDistance = Game.steal.stealMinDistance +
Game.steal.stealDistancePerLevel * Double(Main().level())
if Main().getStealBoost() {
allowedDistance += 250
}
//print("distance:", streetDistance, "allowed:", allowedDistance)

guard let user = street["current_owner"] as? PFUser else { continue }
if user != PFUser.current() && streetDistance <= allowedDistance {
print("found steal")
self.stealobject = street
break
}
}
}
} else {
print("checkin steal failed")
stealButton.isEnabled = false
return
}
print("nearbystreet count:", nearbystreets.count)

if !self.timecheat && stealobject != nil {
stealButton.isEnabled = true
} else {
stealButton.isEnabled = false
}
}

最佳答案

使用 Parse 本地数据存储重写了该函数,从而解决了这个问题。

func checkStealRange() {

stealobject = nil

let query = PFQuery(className: "SHStreets")
if let currentLocation = self.locationManager.location {
let userGeoPoint = PFGeoPoint(latitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
query.whereKey("geo", nearGeoPoint: userGeoPoint, withinKilometers: 5)
} else {
print("no location, returning from check steal range")
self.stealButton.isEnabled = false
return
}
query.fromLocalDatastore()
query.findObjectsInBackground { (objects : [PFObject]?, error: Error?) in

if error != nil {
print(error as Any)
self.stealButton.isEnabled = false
return
}

if objects == nil || objects!.count == 0 {
print("no nearby streets loaded to check for steal")
self.stealButton.isEnabled = false
return
}

if objects != nil {

for (index, object) in objects!.enumerated() {
guard let lon = object["lon"] as? Double else { continue }
guard let lat = object["lat"] as? Double else { continue }
let locationStreet = CLLocation(latitude: lat, longitude: lon)

if let currentLocation = self.locationManager.location {
let distance = currentLocation.distance(from: locationStreet)

//steal distance
var allowedDistance = Game.steal.stealMinDistance + Game.steal.stealDistancePerLevel * Double(Main().level())
if Main().getStealBoost() {
allowedDistance += 250
}

print("distance for street:" , index + 1, "is", distance, "allowed:", allowedDistance)

guard let user = object["current_owner"] as? PFUser else { continue }
if user != PFUser.current() && distance <= allowedDistance {
print("found steal")
self.stealobject = object

if !self.timecheat && self.stealobject != nil && !self.stealinprogress {
self.stealButton.isEnabled = true
} else {
self.stealButton.isEnabled = false
}
return
}
}
}
}
}
}

关于ios - 崩溃:libsystem_pthread.dylib:_pthread_wqthread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44257197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com