Crashlytics iOS - log caught exception

戏子无情 提交于 2019-12-28 05:16:27

问题


I found a way to log custom caught exceptions in the Crashlytics Android SDK, but I can't find anything like that for the iOS SDK. Is there a way to log a caught exception with Crashlytics on iOS?

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


回答1:


Mike from Crashlytics and Fabric here.

You can now capture logged NSErrors in your iOS, tvOS, or OS X app. You want to use:

[CrashlyticsKit recordError:error];

or

Crashlytics.sharedInstance().recordError(error)

This will let you capture a fair number of logged NSErrors per user session. These are only sent on app relaunch. Logged errors errors are grouped by the error domain and code. This means error issues can span many different call sites.

See Documentation




回答2:


Finally Crashlytics added the desired feature 3.5.0!!

[CrashlyticsKit recordError:error];

or

Crashlytics.sharedInstance().recordError(error)

Reference

/**
 *
 * This allows you to record a non-fatal event, described by an NSError object. These events will be grouped and
 * displayed similarly to crashes. Keep in mind that this method can be expensive. Also, the total number of
 * NSErrors that can be recorded during your app's life-cycle is limited by a fixed-size circular buffer. If the
 * buffer is overrun, the oldest data is dropped. Errors are relayed to Crashlytics on a subsequent launch
 * of your application.
 *
 * You can also use the -recordError:withAdditionalUserInfo: to include additional context not represented
 * by the NSError instance itself.
 *
 **/
- (void)recordError:(NSError *)error;
- (void)recordError:(NSError *)error withAdditionalUserInfo:(nullable CLS_GENERIC_NSDICTIONARY(NSString *, id) *)userInfo;

https://docs.fabric.io/ios/changelog.html#january-7-2016


HISTORY

This actually doesn't work as I expected: The message is saved into Crashlytics but only after the app is restarted and it will only save the last message.

So far non of the solutions mentioned here works. There is no way to track handled exceptions in iOS using Crashlytics.


You can use this to log any exception

[[Crashlytics sharedInstance] recordCustomExceptionName:@"HandledException" reason:@"Some reason" frameArray:@[]];

In Crashlytics you'll see it in the crash report but with the NON-FATALS type.

Event if it's not it's intended usage exceptions are logged in the same way Android handled exceptions are.

This is available in version 3.0.7.

recordCustomExceptionName:reason:frameArray:

This method can be used to record a single exception structure in a report. This is particularly useful when your code interacts with non-native languages like Lua, C#, or Javascript. This call can be expensive and should only be used shortly before process termination. This API is not intended be to used to log NSException objects. All safely-reportable NSExceptions are automatically captured by Crashlytics.

https://docs.fabric.io/appledocs/Crashlytics/Classes/Crashlytics.html#//api/name/recordCustomExceptionName:reason:frameArray:




回答3:


It is not possible to log a caught exception in iOS using Crashlytics SDK. CLS_LOG can be used to log custom messages, but these log messages will go to Crashlytics only with the next crash data. If there is no crash, these log messages will never land in the Crashlytics dashboard. I got an official confirmation from the Crashlytics support team regarding the same. Logging caught exceptions in iOS is there in their roadmap.




回答4:


I have gone through different sites for this functionality to be supported for IOS alternate to Crashlytics.

I found crittercism is the best so far..@Dima I think it is the alternative to Crashlytics..try it.

Here are some links that are useful to integrate crittercism in your project...!

http://docs.crittercism.com/ios/ios.html#logging-handled-exceptions

http://www.raywenderlich.com/34050/overview-of-ios-crash-reporting-tools-part-2

@try {

     } 
@catch (NSException *exc) 
     {
        [Crittercism logHandledException:exc]
    }

Refer those links and see it is useful to you or not...!




回答5:


Use below lines in catch block to handle custom caught exception

NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
handler(exception);

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



来源:https://stackoverflow.com/questions/23118742/crashlytics-ios-log-caught-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!