5 Replies
      Latest reply: Nov 18, 2016 2:44 AM by eskimo RSS
      WCSOlet Level 1 Level 1 (0 points)

        I am a solo developer at a government agency. This presents some interesting challanges. First and foremost, I create apps that are not able to access internet resources, and thus I don't have access to some tools that would provide the easy answer to a lot of my problems.

         

        My current problem is that I don't have the ability to use some of the very robust error handeling products out there. However, I need a way to capture crashes on devices that are not teathered to my workstation. I need robust reporting and the ability to see logs for anything that happened on devices that are deployed in places that are not accessable to me easily (think maximum security portion of a ****).

         

        My current thought is capturing every error and sending it to an internal webservice. However, I don't know how to do this without surronding every single line in a try catch.

         

        Does anyone have any experience with this, or with something else entirely that would get me the information I need to debug crashes?

         

        Thanks in advance

        • Re: In Swift, how do I capture every error and send it to a webservice?
          eskimo Apple Staff Apple Staff (7,960 points)

          You need to understand that there are three different types of errors in play here:

          • machine exceptions, like accessing unmapped memory

          • language exceptions, where Objective-C (or C++) code throws an exception

          • Swift errors

          Swift’s try/catch mechanism will only catch Swift errors.  Catching the others is quite a bit trickier.

          In general I strongly recommend against implementing your own crash reporting mechanism.  It is impossible to make one that’s as reliable as the mechanism built in to the system.  However, if you’re working in a secure environment then the Apple crash reporter is not going to work for you.

          It seems to me that MDM should provide a crash reporting facility for users like you.  AFAIK it does not, but that would make a fine enhancement request.  Please post your bug number, just for the record.

          Given the above it seems that you’ll need your own crash reporter.  I wouldn’t try to write one from scratch; it’s a lot of ugly low-level code.  Instead I recommend that you adapt one of the existing solutions.  I don’t have a specific recommendation for you because I don’t have any experience with them (as I mentioned above, I strongly recommend that normal developers stick with the Apple crash reporter), so you’ll have to dig into this yourself.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: In Swift, how do I capture every error and send it to a webservice?
              WCSOlet Level 1 Level 1 (0 points)

              Any chance there is a way to write to a local (on device) log that can be accessed later?

                • Re: In Swift, how do I capture every error and send it to a webservice?
                  KMT Level 8 Level 8 (9,960 points)

                  Sure, if you don't mind connecting the devices to Xcode later, and are willing to compromise the results, meaning you'll mainly get what you trap...but you indicated above that those weren't an option, so...

                   

                  As Eskimo states, the system you want isn't recommended.

                  • Re: In Swift, how do I capture every error and send it to a webservice?
                    eskimo Apple Staff Apple Staff (7,960 points)

                    Any chance there is a way to write to a local (on device) log that can be accessed later?

                    Crash reports will be written to disk by the built-in Apple crash reporter.  They’ll then be uploaded to your Mac (or Windows machine) the next time you sync.  The process for doing this is described in Technote 2151 Understanding and Analyzing iOS Application Crash Reports.

                    The gotcha here is that this is a very manual process.  If your users are syncing their devices for other reasons, you could run code on their Mac to grab these crash reports and upload them to your internal system.  However, if the user’s don’t sync their devices regularly, these crash reports will remain stuck on the device until they next sync.

                    You can’t access these crash report from code running on the device because they are ‘owned’ by the system, and thus walled off from your app by the sandbox.

                    The alternative is to build your own in-app crash reporter that writes its crash reports to some place in your app’s container, whereupon the app can upload the crash report to wherever it wants when it’s next launched.  The key problem with this is that the first step, building your own crash reporter, which has two major drawbacks:

                    • It’s a bunch of gnarly low-level code

                    • It will reduce the quality of your crash reports, because it’s impossible to make a crash reporter that’s as reliable as the mechanism built in to the system

                    Regardless of what else you do here, please do take the time to file an enhancement request for MDM support for this.

                    Share and Enjoy

                    Quinn “The Eskimo!”
                    Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                    let myEmail = "eskimo" + "1" + "@apple.com"