问题
I'm having a problem similar to [xCode 9.3 and Firebase Crashlytics not working. I am able to force a crash in the debug version of the main app and the crash appears in the console on Fabric.io. I have also made a way (using an "Easter egg") to force a crash in the framework code. I have tried three different approaches. The first two are attempts to simulate a "real" crash originating in the framework code itself. The third uses a "bogus" callback to the main app. Note that in the code below, I'm showing all three approaches together, but in real life, I comment two of them out in order to test a single approach:
//#1
@throw ([NSException exceptionWithName:@"CrashlyticsForce" reason:@"Easter egg hit" userInfo:nil]);
//#2
NSDecimalNumber *i = [NSDecimalNumber decimalNumberWithDecimal:[@(1) decimalValue]];
NSDecimalNumber *o = [NSDecimalNumber decimalNumberWithDecimal:[@(0) decimalValue]];
// Divide by 0 to throw an exception
NSDecimalNumber *x = [i decimalNumberByDividingBy:o];
//#3 The following DOES work, but it's really lame because the crash
// actually gets forced in the main app via this bogus call to a
// protocol method implemented in the app for the sole purpose of
// enabling the engine to force a crash.
[(NSObject <NSAlertDelegate> *)[NSApp delegate] alertShowHelp:
[NSAlert alertWithMessageText:@"Forcing an error" defaultButton:nil
alternateButton:nil otherButton:nil
informativeTextWithFormat:@"Forcing error from framework!"]];
NSLog(@"Crashlytics - KME: You should not be seeing this line!");
For the third approach, the main app handles the callback by calling
[[Crashlytics sharedInstance] crash];
When using approach #3, Crashlytics immediately uploads the simulated crash to the Fabric.io console, where I can see. The failing approaches do not. It's not clear whether they actually cause the app to crash, although control does leave the method (because the final NSLog statement never shows up in Console. The app is an Input Method, so the OS may be restarting it automatically. I have tried restarting the computer immediately following the forced crash, because I know that typically Crashlytics will not transmit the crash until the app is restarted. When I do that I see the following in Console upon restarting the app:
[Crashlytics] Version 3.10.1 (129)
[Crashlytics] Running on MacBookPro11,4, 10.13.4 (17E202)
[Answers] Initialized
[Fabric] Initialized with kit versions: {
"com.twitter.answers.mac" = "1.3.7";
"com.twitter.crashlytics.mac" = "3.10.1";
"io.fabric.sdk.mac" = "1.7.6";
}
Faulting in NSHTTPCookieStorage singleton
Faulting in CFHTTPCookieStorage singleton
Creating default cookie storage with process/bundle identifier
Initializing Keyman Input Method with server: <IMKServer: 0x6040000147b0>
TIC Enabling TLS [1:0x6040001717c0]
TIC TCP Conn Start [1:0x6040001717c0]
Task <3C62019C-7486-469F-B4AE-9D4DDC7DB101>.<1> setting up Connection 1
[1 <private> <private>] start
New active app com.lastpass.LastPass
sender <IPMDServerClientWrapper: 0x6080002805f0>
TIC TLS Event [1:0x6040001717c0]: 1, Pending(0)
TIC TLS Event [1:0x6040001717c0]: 2, Pending(0)
UNIX error exception: 17
UNIX error exception: 17
UNIX error exception: 17
TIC TLS Event [1:0x6040001717c0]: 11, Pending(0)
TIC TLS Event [1:0x6040001717c0]: 12, Pending(0)
TIC TLS Event [1:0x6040001717c0]: 14, Pending(0)
System Trust Evaluation yielded status(0)
TIC TLS Trust Result [1:0x6040001717c0]: 0
TIC TLS Event [1:0x6040001717c0]: 20, Pending(0)
TIC TCP Conn Connected [1:0x6040001717c0]: Err(16)
TIC TCP Conn Event [1:0x6040001717c0]: 1
TIC TCP Conn Event [1:0x6040001717c0]: 8
TIC TLS Handshake Complete [1:0x6040001717c0]
Task <3C62019C-7486-469F-B4AE-9D4DDC7DB101>.<1> now using Connection 1
Task <3C62019C-7486-469F-B4AE-9D4DDC7DB101>.<1> sent request, body N
Task <3C62019C-7486-469F-B4AE-9D4DDC7DB101>.<1> received response, status 200 content K
Task <3C62019C-7486-469F-B4AE-9D4DDC7DB101>.<1> response ended
[Fabric] settings downloaded successfully
[Fabric] Settings are available for consumption
TIC TCP Conn Cancel [1:0x6040001717c0]
[1 <private> stream, pid: 649, url: https://settings.crashlytics.com/spi/v2/platforms/mac/apps/keyman.inputmethod.Keyman/settings?build_version=10.0.0&display_version, tls] cancelled
[1.1 074D1109-26C9-44B8-834C-F53EF153DACA <private>.49357<-><private>]
Connected Path: satisfied (Path is satisfied), interface: en0, ipv4, dns
Duration: 0.218s, DNS @0.000s took 0.020s, TCP @0.024s took 0.023s, TLS took 0.123s
bytes in/out: 7265/1338, packets in/out: 9/3, rtt: 0.019s, retransmitted packets: 0, out-of-order packets: 0
2018-05-25 10:43:13.267599 -0400 Keyman [Answers] Answers enabled with settings: {
"flush_interval_secs" = 300;
"flush_on_background" = 1;
"forward_to_google_analytics" = 0;
"include_purchase_events_in_forwarded_events" = 0;
"max_byte_size_per_file" = 8000;
"max_file_count_per_send" = 1;
"max_pending_send_file_count" = 100;
"sampling_rate" = 1;
"track_custom_events" = 1;
"track_predefined_events" = 1;
"track_view_controllers" = 0;
url = "https://e.crashlytics.com/spi/v2/events";
}
[Answers] Logging events to /Users/tom/Library/Caches/com.crashlytics.data/keyman.inputmethod.Keyman/analytics/v2/events
[Answers] Transmitting packaged events for '87099A49-DC62-4E10-AB2D-A98394173E21'.
TIC Enabling TLS [2:0x60c000171340]
TIC TCP Conn Start [2:0x60c000171340]
Task <CCB3C9EE-3123-42F8-A98D-D009EBF34DEB>.<1> setting up Connection 2
[2 <private> <private>] start
TIC TLS Event [2:0x60c000171340]: 1, Pending(0)
TIC TLS Event [2:0x60c000171340]: 2, Pending(0)
TIC TLS Event [2:0x60c000171340]: 11, Pending(0)
TIC TLS Event [2:0x60c000171340]: 12, Pending(0)
TIC TLS Event [2:0x60c000171340]: 14, Pending(0)
System Trust Evaluation yielded status(0)
TIC TLS Trust Result [2:0x60c000171340]: 0
TIC TLS Event [2:0x60c000171340]: 20, Pending(0)
TIC TCP Conn Connected [2:0x60c000171340]: Err(16)
TIC TCP Conn Event [2:0x60c000171340]: 1
TIC TCP Conn Event [2:0x60c000171340]: 8
TIC TLS Handshake Complete [2:0x60c000171340]
Task <CCB3C9EE-3123-42F8-A98D-D009EBF34DEB>.<1> now using Connection 2
Task <CCB3C9EE-3123-42F8-A98D-D009EBF34DEB>.<1> sent request, body S
Task <CCB3C9EE-3123-42F8-A98D-D009EBF34DEB>.<1> received response, status 200 content K
Task <CCB3C9EE-3123-42F8-A98D-D009EBF34DEB>.<1> response ended
[Answers] Finished transmission of '87099A49-DC62-4E10-AB2D-A98394173E21'.
LSExceptions shared instance invalidated for timeout.
In the production version of the app, I am seeing real crashes on Fabric.io that occur in the framework code. The production versions uses a different API code and it's built in release rather than debug, but I think I have all the symbol stripping and dSYM creation settings the same for Debug and Release. Also, FWIW, I tried using the #1 and #2 code to force the crash in the callback in main app (instead of calling [[Crashlytics sharedInstance] crash]), and Crashlytics does not report it from there either. So it doesn't seem to have anything to do with the framework itself.
来源:https://stackoverflow.com/questions/50479344/crashlytics-not-transmitting-crash-event-to-fabric-io-debug-mode-only