简体   繁体   English

在设备上运行但不在Swift的Simulator中运行时的断点

[英]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.

相关问题 断点异常在模拟器和设备中运行时发生 - Breakpoint exception occurs on run in simulator and device Spritekit 应用程序在设备上运行时崩溃,在 swift 3 转换后可在模拟器上运行 - Spritekit app crashes when run on device, works on simulator after swift 3 conversion Swift UITableView在模拟器中工作,但我在设备上运行时遇到错误 - Swift UITableView works in simulator but i'm facing an error when i run it on device NSDictionary…代码在模拟器上运行时效果很好,但在设备上运行时效果不佳 - NSDictionary…code works fine when run on simulator but not when run on device 在模拟器上运行设备构建 - Run device build on simulator 当检查nil时,Swift Optional有时会在设备上崩溃,但不会在模拟器上崩溃 - Swift Optional sometimes crashes on device but not on simulator when checking nil Swift Admob控制台显示模拟器设备ID,但在iPhone上运行时却没有? - Swift Admob console displays simulator device ID but not when running on iPhone? 尝试使用XCode 5在iPhone模拟器上运行iOS应用程序时不断出现断点错误 - Keep getting breakpoint error when trying to run iOS application on iphone simulator with xcode 5 Swift:声音在模拟器上播放,但不在设备上播放 - Swift: Sound plays on simulator but not on device Swift应用程序在模拟器上打开但不在设备上打开 - Swift App Opens on Simulator But Not on Device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM