Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a log to Crashlytics without an app crash

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?

like image 804
jack Avatar asked Jul 25 '14 07:07

jack


3 Answers

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.

like image 83
Tiago Almeida Avatar answered Nov 07 '22 14:11

Tiago Almeida


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.

like image 25
Rui Peres Avatar answered Nov 07 '22 14:11

Rui Peres


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

like image 8
Aanabidden Avatar answered Nov 07 '22 16:11

Aanabidden