Parsing error log messages to String in iOS - ios

Is there a way to parse iOS's log to a String at run time when it occurred? I need to parse a certain error log from UIKit and assert it at once when it appeared for debugging.
What we want to do is to parse the console for this error: This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. We've found and fixed the line that causes this error, but we need to prevent this for happening again. FYI, the culprit is a line that changes a constant of an Autolayout in a background thread. And unfortunately it is not recognized by the compiler as an error like when we do the same thing with UIButton or anything that is derived from UIView (which will give an error at compile time when we try putting it in a background thread).

After much googling for the answer, I've finally found the answer. I found this article:
So here's what I did:
Eavesdropping on stderr stream
Duplicate it into another string
Parse the string for "weird crashes"
If found, it will crash immediately (instead of still running the app and waiting for the app to crash at indefinite time)
Added a DEBUG guard so that this functionality doesn't get carried over to production

Related

Adding a breakpoint to breakpoint navigator for a Core Data error

I'm trying to track down a bug in an app which logs an error in the simulator, but doesn't crash in the simulator or on my testing device. I think I've got a handle on what to do once I can figure out where the problematic code is located, but I'm having a heck of a time figuring out what call is generating it.
CoreData: error: Failed to call designated initializer on NSManagedObject class "OneOfMyManagedObjects"
I'd like to add a breakpoint that stops execution on that error. How would I set the breakpoint navigator to stop execution when that error is logged in the console?
What I've Tried:
So far, I threw some log statements in AppDelegate.swift and the initial ViewController to "see what's going on". Additionally, I've thrown in some manual breakpoints in hopes of tracking down the issue that's generating the console error, but it's taking forever and a day to step through everything. Given the issue lives somewhere between AppDelegate and viewDidLoad of the initial ViewController, I'm baffled why it's taking me so long to spot the problem.
I've added an exception breakpoint for all exceptions in the breakpoint navigator, but this error doesn't appear to be enough to stop execution. I do think it's enough to cause a problem for a minority of users, which is why I'm trying to clean it up.
Special thanks to pbasdf for pointing me in the right direction.
My app uses a TabBarController with 4 tabs. The initial tab is tab 0, so I was looking for a problem between AppDelegate.swift and InitialVC's viewDidLoad. In reality, my problem lived on Tab3ViewController where OneOfMyManagedObjects are displayed.
I had a global variable set on Tab3ViewController that looked like this:
// this was the problem
var oneOfMyManagedObjectsToEdit = OneOfMyManagedObjects()
// I changed it to this and the error went away
var oneOfMyManagedObjectsToEdit: OneOfMyManagedObjects?
Thank you for pointing me in the right direction towards resolution of this problem.

"CoreUI: didn't find parent rendition for" debug message

After updating to Xcode 7.2 I started getting the "CUICatalog: Invalid Request: requesting subtype without specifying idiom" debug message. Upon googling this message I found my way to another post on SO: CUICatalog: Invalid Request: requesting subtype without specifying idiom which led me to believe that SKSpriteNode(imageNamed: "my_image") somehow was causing the messages.
I worked around the issue by altering these lines of code to SKSpriteNode(texture: SKTextureAtlas(named: "MySprites").textureNamed("my_image")). To make this work I created a folder called MySprites in my Images.xcassets, checked its "Provides Namespace" checkbox and moved all assets into it.
At first, this seemed to be working, but then I started getting the debug message "CoreUI: didn't find parent rendition for 'MySprites/my_image' skipping it" instead. The weird thing is, everything seems to be working as it's supposed to. Only, my debugger log window gets completely spammed with this mysterious message which off course makes debugging hard.
I have no idea what I'm doing wrong. Why am I getting this message? Is there a Sprite Kit guru out there who can point me in the right direction?
If there is something I can do to clarify the issue, please let me know. I find it hard to believe that I am the only one experiencing this.

iOS EXC_BAD_ACCESS: How to debug?

I am getting an EXC_BAD_ACCESS. I know what this usually means: Trying to access an object that doesn't exist (anymore) is the most likely cause.
So, where do I find that?
I have read numerous posts on the internet, and they all say:
"Enable NSZombie" in the scheme.
Now when I run the debugger, for what should I look? I can not see any difference...
Note: This is not about a perticular error in my code, but generally how to use the debugger with NSZombie enabled
What I would do it will be to locate a breakpoint just one line above the green arrow showing the EXC_BAD_ACCESS error. Then run again your code and reproduce the steps to generate the crash.
When you get to your breakpoint you can check that your objects are valid objects using right click and print description in the left side of your console within Xcode or typing the command 'po' within the console section in XCode. That's how I usually detect the errors.
Something useful is to trace the stack once the debugger stopped. It show in the left panel the threads and chain of invocations of the methods before the break point.
Hope this helps and hope my description of the alternative in how to track the error helps.
Write code in #synchronized(){} block.
Try this:
#synchronized (self){ //Your Code }

CGContext errors in iOS application

When I run my application it works well, but during transitions between its views I have a lot of CGContext errors in the console output, but the app still works well, no crashes or bugs I didn't see. Description: so I only run my app - all work well - but there appears error messages in the console:
And after any other view transition they appear again and again. So the question - how to fix this? And what may be the reason of this error messages? There a lot of views and code in my application so I don't even know what part is error-prone.But these messages appear after transitions between all views in my app. Thanks in advance.
Look for some method in your code where you call CGContextSaveGState, CGContextSetBlendMode, CGContextSetApha, etc. Chances are that you won´t find many places where you do that.
Well, if you find it, look for some statement (just before those listed in your console log) where a context is created, and try to understand why it fails. You may set a breakpoint on that line and inspect the parameters to the CGContextCreate call.
If you need more help, paste the code you have (hopefully) found.

Error deserializing wallpaper image : iPad

What does the following error indicates
5/19/11 8:06:45 PM SpringBoard[9712] Error deserializing
wallpaper image: Error
Domain=CPBitmapErrorDomain Code=0 "The
operation couldn’t be completed.
(CPBitmapErrorDomain error 0 - No data
provided to
CPBitmapCreateImagesFromData)"
UserInfo=0x70b9c80 {NSDescription=No
data provided to
CPBitmapCreateImagesFromData}
Well, if you read the error message, it is telling you that a wallpaper was unable to be deserialised because no data was provided to the function named CPBitMapCreateImagesFromData. Pretty self explanitory.
Other than that, it sounds like you're either working on a jailbroken phone or trying to do things that aren't supported by the official iOS SDK - in which case my help ends here.
Or you're a user who is trying to understand why an image they set as a wallpaper isn't displaying and found their way to the iPad's console - in which case, this isn't the place to be asking.
This happened to me also, I think it's because most of the tutorials are written with an iphone in mind and I was using an iPad. I was working with an ipad and when following these tutorials i was getting this problem.
When you are creating the project I choose View based application. In the same wizard there's a combo box for 'iPhone' and 'iPad'.. If I leave that as iPhone then my application doesnt start in the simulator and I see the error you mention. If I set that to iPad then everything works fine.
I dont understand why that should make a difference tbh..
This happened to me, but only when I was not debugging, what happened was that in the dealloc function [super dealloc] was called at the top of the function rather than at the end. The "deserializing wallpaper" message is probably due to some sort of memory corruption that occurred since I had code after [super dealloc] trying to use pointers that were now garbage. I had NSZombie activated but it had no effect. Why this only crashed when I was not hooked up to the debugger is beyond me at the moment.
Thankfully this bug was fixed after a few diffs in source control, but initially I was pretty perplexed at the message and the fact that it was a bug where the debugger couldn't be used only induced more panic.
I'm sure you've long fixed your problem but I thought it'd be helpful to put this out there for others.

Resources