Send a log to Crashlytics without an app crash - ios

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?

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.

Kinda old question, but now you can use Answers which is part of the Fabric suit (Crashlytics is part of Fabric as well):
Fabric can be found here. And further documentation here.

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

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)
}

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)

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

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

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

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 !

Related

EXC_BAD_ACCESS error in swift with getting data from firebase

I am connecting to Firestore from iOS.
But when I ran this code it gave me a EXC_BAD_ACCESS error.
db.collection("chats").document(code).setData(["users":[Constants.User.currentUID!]]) { (err) in
if err != nil{
print("error registering with firebase")
}
else{
//...
}
}
So I went to the scheme editor and enabled the Address Sanitizer.
The error I got was highlighting code and said:
Thread 1: Use of deallocated memory
When I click on code it does show its correct value of QAWQ
What do I do?
EDIT
Under further investigation it is wherever the variable code is used

Authenticating the user with biometrics causing application to crash

So i'm following the books in terms of authenticating a user using biometrics. Below is some code i've wrote in a custom class called biometrics manager.
func authenticateUser(completion: #escaping (_ result: BiometricsStatus) -> Void) {
DispatchQueue.main.async {
guard self.deviceHasBiometricCapabilities() else { completion(.fail(error: .touchIDNotAvailable)); return }
let authMethod = self.biometricType() == .faceID ? "Face ID" : "Touch ID"
let loginMessage = "\(authMethod) to sign in"
self.context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: loginMessage) { success, evaluateError in
if success {
completion(.success)
return
}
if let error = evaluateError {
completion(.fail(error: self.getBiometricsError(from: error)))
return
}
}
}
}
I've debugged my application and it seems to be causing a crash on the evaluate policy line, i've enabled exception breakpoints to try and catch the crash but i'm receiving nothing at all in the console logs. The only thing that i seem to be getting in the console is the following.
Message from debugger: Terminated due to signal 9
Which isn't super helpful any possible pointers or ideas that may be causing this crash to occur at all?
You need to add the NSFaceIDUsageDescription key to your info.plist
From https://developer.apple.com/documentation/localauthentication/lacontext
Important
Include the NSFaceIDUsageDescription key in your app’s Info.plist file if your app allows biometric authentication. Otherwise, authorization requests may fail.

RPScreenRecorder stopRecording block not getting called

I have searched enough but failed to get a solution.
I am using ReplayKit to record the screen of my app. I have started recording the screen by calling
let sharedRecorder = RPScreenRecorder.shared()
sharedRecorder.startRecording() { error in
if let error = error {
self.showScreenRecordingAlert(message: error.localizedDescription)
}
}
When I am pressing the stopRecord button I am calling
let sharedRecorder = RPScreenRecorder.shared()
sharedRecorder.stopRecording { previewViewController, error in
if let error = error {
self.showScreenRecordingAlert(message : error.localizedDescription)
return
}
}
But the issue that I am facing is, the program control does not enter inside the stopRecording block.
When I am doing po sharedRecorder.isRecording, it always returns false.
I have done everything I know but failed to get a solution.
If you having this above issue with your code i have found the solution for this.
let sharedRecorder = RPScreenRecorder.shared()
sharedRecorder.stopRecording { previewViewController, error in
if let error = error {
self.showScreenRecordingAlert(message : error.localizedDescription)
return
}}
Above Block will not call if you running your app on simulator so please use real device to test then above method will call definitely.
Thank you.
Just had this issue running XCode 9.4.1 and building onto iOS 11.4.0. Upgrading the phone to iOS 11.4.1 fixed the bug. I'm not sure if the difference in XCode versions is the root cause or if 11.4.0 was just broken.

Crashlytics logging of Swift Try-Catch

I'm facing a weird issue where Crashlytics is logging caught exceptions from within a try-catch block.
Here's some sample code:
do {
try managedContext.save() // Exception!!!
} catch let error as NSError {
error = error
print("Could not save \(error), \(error?.userInfo)")
}
The try-catch block is supposed to prevent crashes, and yet this line is logged by Crashlytics as an issue (and NOT a non-fatal). How is this possible?
Some background info:
The managedContext object is of type NSManagedObjectContext, which is initialized by the AppDelegate (written in Objective-C).
I'm using the latest version of Fabric - 2.3.0
What's going on?

Parse saveInBackgroundWithBlock crashes on iOS

I am adding some data into my parse class (table) successfully.
After saving is successfully completed (I can see the data on website), my app crashes without leaving any message on console. I tried to get a message by using "Enable Zombie Objects" setting. This is the message I am getting which has nothing to do what I am doing:
-[UIActivityIndicatorView release]: message sent to deallocated instance 0x126d16780
I do not have any UIActivityIndicatorView in my whole project.
This is how I save my data:
var currentUser = PFUser.currentUser()!
var userCase = PFObject(className: "Case")
userCase.relationForKey("user").addObject(currentUser)
userCase["caseCode"] = "test_code"
userCase.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
println("saved")
} else {
// There was a problem, check error.description
println("error occurred: \(error?.description)")
}
}
Swift SDK version: 1.7.5
Xcode version: 6.4
Has anybody have ever faced with such problem?
UPDATE: This error does not occur on simulator (tested on iPhone 5, iPhone 5S, iPhone 6) and does not occur on device at first run.
Tried removing and re-installing the app.
UPDATE 2: Removing PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions) or changing it to PFFacebookUtils.initialize() from AppDelegate fixes the issue but I think I need to use initializeFacebookWithApplicationLaunchOptions(launchOptions). I have another problem now.
You may do the following.
1) Go to PFFacebookUtils.h
2) change:
(void)initializeFacebookWithApplicationLaunchOptions:(NSDictionary *)launchOptions;
To:
(void)initializeFacebookWithApplicationLaunchOptions:(PF_NULLABLE NSDictionary *)launchOptions;
It was originally posted here

Resources