Send a log to Crashlytics without an app crash

IosCrashlytics

Ios Problem Overview


How can I get Crashlytics to receive a log without my app crashing? I have the following code:

if(!context.managedObjectContext save:&error) {
    CLS_LOG(@"%@",error.description)
}

When an error occurs, I want the Crashlytics server to receive the error but the app should continue running.

I do not need the log right away. I would be happy to get the log on the next restart. I just do not want to have to trigger a crash in my app to receive the log.

Is this possible?

Ios Solutions


Solution 1 - Ios

With the new update from crashlytics you can now use:

[[FIRCrashlytics crashlytics] recordError:error];

And in Swift:

Crashlytics.crashlytics().record(error: error)

You can check the documentation here.

Solution 2 - Ios

Kinda old question, but now you can use Answers which is part of the Fabric suit (Crashlytics is part of Fabric as well):

enter image description here

Fabric can be found here. And further documentation here.

Solution 3 - Ios

I tried the below lines and it works like charm. In try-catch block use the below lines in your catch block

@try {
// line of code here
}
@catch (NSException *exception) {
NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
handler(exception);
}

as explained at http://support.crashlytics.com/knowledgebase/articles/222764-can-i-use-a-custom-exception-handler

[UPDATE]

Now in fabric's crashlytics we can use simple function [Crashlytics recordCustomExceptionName:reason:frameArray:] for sending handled exceptions

@try {
// line of code here
}
@catch (NSException *exception) {
    NSArray *stack = [exception callStackReturnAddresses];
    [[Crashlytics sharedInstance] recordCustomExceptionName: exception.name
                                                 reason: exception.reason
                                             frameArray: stack];
}

as explained at https://twittercommunity.com/t/crashlytics-ios-how-to-send-non-fatal-exceptions-without-app-crash/34592/32

Solution 4 - Ios

For me the method .recordError() didn't helped, because it don't log the user information. Or i just didn't found where to watch it. Using recordCustomExceptionName fit to me. There is an example of implementation of the both ways:

func logMessage(_ message: String) {
    let userInfo = ["message" : message]
    let error = NSError(domain: "AppErrorDomain", code: 1, userInfo: userInfo)
    Crashlytics.sharedInstance().recordCustomExceptionName("API Error", reason: message, frameArray: [])
    Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo: userInfo)
}

Solution 5 - Ios

Swift 5, Crashlytics SDK 4.0.0-beta.6:

let exceptionModel = ExceptionModel(name: "exception title", reason: "details")
Crashlytics.crashlytics().record(exceptionModel: exceptionModel)

...similar for NSError, with whatever you want to see in the Crashlytics dashboard.

let error = NSError(domain: "error title", code: 0, userInfo: ["message":"some details"])
Crashlytics.crashlytics().record(error: error)

Solution 6 - Ios

Crashlytics is a crash tracking service, if you need to track custom messages choose other analytics service.

Solution 7 - Ios

In reference from Crashlytics documents.

try {
  myMethodThatThrows();
} catch (Exception e) {
  Crashlytics.logException(e);
  // handle your exception here!
}

https://docs.fabric.io/android/crashlytics/caught-exceptions.html?caught%20exceptions#caught-exceptions

Solution 8 - Ios

As far as I know, if you dont protect your code correctly, your application will crash anyway. Crashlylytics, take this crashes and show them to you in a "readable" mode in the web application they have designed. If there is no crash, crashlytics will take anything. You can grab an exception in your code :

@try{
....
}
@catch(NSException ex){...}

in the critical parts, but you should always do that if you are afraid your application is going to crash or you find a potential error which can allow your application have a bad behavior and acting up. You can always force in your exception to send or track this error.

Hope it helps

Solution 9 - Ios

The trick is to use the following :

http://support.crashlytics.com/knowledgebase/articles/202805-logging-caught-exceptions

Just use this :

Crashlytics.logException(new Exception("my custom log for crashLytics !!!"));

I use this and I get my non-fatal crash in about 5 minutes !

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjackView Question on Stackoverflow
Solution 1 - IosTiago AlmeidaView Answer on Stackoverflow
Solution 2 - IosRui PeresView Answer on Stackoverflow
Solution 3 - IosAanabiddenView Answer on Stackoverflow
Solution 4 - IosNike KovView Answer on Stackoverflow
Solution 5 - Ioswildcat12View Answer on Stackoverflow
Solution 6 - IosavdyushinView Answer on Stackoverflow
Solution 7 - IosMuhammad Aamir AliView Answer on Stackoverflow
Solution 8 - IosAlfuryDBView Answer on Stackoverflow
Solution 9 - IosTobliugView Answer on Stackoverflow