[英]Breakpoint when run on device but not in Simulator in Swift
I run this app on the Simulator normally but when I tried it on an actual Device it crashes but unlike most breakpoints there was no message just a "Lost connection to Device" popup. 我通常在模拟器上运行此应用程序,但是当我在实际的设备上尝试运行该应用程序时,它崩溃了,但与大多数断点不同的是,没有消息只是“失去与设备的连接”弹出窗口。 It happens every time I run it on a device but never in the Simulator. 每次我在设备上运行它时都会发生这种情况,但是在模拟器中却没有。 It's not a problem with the connection wire. 连接线没有问题。
I have a lot of code but here's the important stuff: 我有很多代码,但这是重要的东西:
print("Test-1")
let imageView2 = uiview
// Find the path where to
save
guard let myFilePath = createMyFilePath(forFileName: "Page1test.png") else {
print("Cannot generate file path ☹️")
exit(0)
}
// Use this to check in finder where your file is saved
print(myFilePath)
print("Test")
// Transform the imageView in UIImage to save it
let imageToSave = createImage(fromView: imageView2)
// Get the image as data
guard let imageToSaveAsData = UIImagePNGRepresentation(imageToSave) else {
print("Cannot transform image to data ☹️")
exit(1)
}
// Save to Disk!
do{
try imageToSaveAsData.writeToFile(myFilePath, options: .DataWritingAtomic)
} catch {
print("Error, cannot write to the location \(myFilePath)")
}
// Load from Disk!
let loadedImageData = NSData(contentsOfFile: myFilePath)
// Check the data is the same
if loadedImageData == imageToSaveAsData {
print("✌️")
}
// Have a look at the loaded image!
var bob = UIImage(data: loadedImageData!)
imageviewloaded.image = bob
//Page 2
let imageViewtest = uiview2
// Find the path where to save
guard let myFilePathtest = createMyFilePath(forFileName: "Page2test.png") else {
print("Cannot generate file path ☹️")
exit(0)
}
// Use this to check in finder where your file is saved
print(myFilePathtest)
// Transform the imageView in UIImage to save it
let imageToSavetest = createImage(fromView: imageViewtest)
// Get the image as data
guard let imageToSaveAsDatatest = UIImagePNGRepresentation(imageToSavetest) else {
print("Cannot transform image to data ☹️")
exit(1)
}
// Save to Disk!
do{
try imageToSaveAsDatatest.writeToFile(myFilePathtest, options: .DataWritingAtomic)
} catch {
print("Error, cannot write to the location \(myFilePath)")
}
// Load from Disk! Page 2
let loadedImageDatatest = NSData(contentsOfFile: myFilePathtest)
// Check the data is the same
if loadedImageDatatest == imageToSaveAsDatatest {
print("✌️")
}
// Have a look at the loaded image!
var bobtest = UIImage(data: loadedImageDatatest!)
var imagecool = UIImageView()
imagecool.image = bobtest
//Page 4
let imageViewPage4 = uiview3
// Find the path where to save
guard let myFilePathPage4 = createMyFilePath(forFileName: "Page4test.png") else {
print("Cannot generate file path ☹️")
exit(0)
}
// Use this to check in finder where your file is saved
print(myFilePathtest)
// Transform the imageView in UIImage to save it
let imageToSavePage4 = createImage(fromView: imageViewPage4)
// Get the image as data
guard let imageToSaveAsDataPage4 = UIImagePNGRepresentation(imageToSavePage4) else {
print("Cannot transform image to data ☹️")
exit(1)
}
// Save to Disk!
do{
try imageToSaveAsDataPage4.writeToFile(myFilePathPage4, options: .DataWritingAtomic)
} catch {
print("Error, cannot write to the location \(myFilePath)")
}
// Load from Disk! Page 4
let loadedImageDataPage4 = NSData(contentsOfFile: myFilePathPage4)
// Check the data is the same
if loadedImageDataPage4 == imageToSaveAsDataPage4 {
print("✌️")
}
// Have a look at the loaded image!
var bobPage4 = UIImage(data: loadedImageDataPage4!)
var imagepage4 = UIImageView()
imagepage4.image = bobPage4
print("Test--2")
I get a printout in the console: 我在控制台中得到了打印输出:
I have no idea whats going on. 我不知道发生了什么事。 Can anyone help? 有人可以帮忙吗?
I think it is memory issue, something related to image size maybe you need to review your code and try to resize images . 我认为这是内存问题,可能与图像大小有关,您可能需要检查代码并尝试调整图像大小。 this answer can help you to figure out why you get this error try to check it communication problem . 这个答案可以帮助您弄清楚为什么会出现此错误,并尝试检查它的通讯问题 。 hope it help 希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.