Skip to content

Commit

Permalink
fix(crashlytics, ios): explicitly set collection opt in/out (#4236)
Browse files Browse the repository at this point in the history
* Explicitly set crash collection setting

PR spawned from discussion here #4227
  • Loading branch information
williamhaley authored Sep 10, 2020
1 parent 55cd752 commit cda4c10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/app/ios_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if [[ ${_SEARCH_RESULT} ]]; then
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_MESSAGING_AUTO_INIT")")
fi

# config.crashlytics_disable_auto_disabler - undocumented for now - mainly for debugging, document if becomes usful
# config.crashlytics_disable_auto_disabler - undocumented for now - mainly for debugging, document if becomes useful
_CRASHLYTICS_AUTO_DISABLE_ENABLED=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "crashlytics_disable_auto_disabler")
if [[ $_CRASHLYTICS_AUTO_DISABLE_ENABLED == "true" ]]; then
echo "Disabled Crashlytics auto disabler." # do nothing
Expand Down Expand Up @@ -137,7 +137,7 @@ for plist in "${_TARGET_PLIST}" "${_DSYM_PLIST}" ; do
if [[ -f "${plist}" ]]; then

# paths with spaces break the call to setPlistValue. temporarily modify
# the shell internal field separator variable (IFS), which normally
# the shell internal field separator variable (IFS), which normally
# includes spaces, to consist only of line breaks
oldifs=$IFS
IFS="
Expand All @@ -155,4 +155,3 @@ for plist in "${_TARGET_PLIST}" "${_DSYM_PLIST}" ; do
done

echo "info: <- RNFB build script finished"

Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,54 @@
#import "RNFBPreferences.h"
#import "RNFBJSON.h"
#import "RNFBMeta.h"
#import "RNFBApp/RNFBSharedUtils.h"

NSString *const KEY_CRASHLYTICS_DEBUG_ENABLED = @"crashlytics_debug_enabled";
NSString *const KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED = @"crashlytics_auto_collection_enabled";

@implementation RNFBCrashlyticsInitProvider

+ (void)load {
if ([self isCrashlyticsCollectionEnabled]) {
[FIRApp registerInternalLibrary:self withName:@"react-native-firebase-crashlytics" withVersion:@"6.0.0"];
}
[FIRApp registerInternalLibrary:self withName:@"react-native-firebase-crashlytics" withVersion:@"6.0.0"];
}

+ (BOOL)isCrashlyticsCollectionEnabled {
BOOL enabled;

if ([[RNFBPreferences shared] contains:KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED]) {
enabled = [[RNFBPreferences shared] getBooleanValue:KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED defaultValue:YES];
DLog(@"isCrashlyticsCollectionEnabled via RNFBPreferences: %d", enabled);
} else if ([[RNFBJSON shared] contains:KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED]) {
enabled = [[RNFBJSON shared] getBooleanValue:KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED defaultValue:YES];
DLog(@"isCrashlyticsCollectionEnabled via RNFBJSON: %d", enabled);
} else {
// Note that if we're here, and the key is not set on the app's bundle, we default to "YES"
enabled = [RNFBMeta getBooleanValue:KEY_CRASHLYTICS_AUTO_COLLECTION_ENABLED defaultValue:YES];
DLog(@"isCrashlyticsCollectionEnabled via RNFBMeta: %d", enabled);
}

DLog(@"isCrashlyticsCollectionEnabled: %d", enabled);

return enabled;
}

+ (NSArray<FIRComponent *> *)componentsToRegister {
return @[];
}

/*
* configureWithApp is automatically invoked by Firebase as this app is a registered FIRLibrary with the SDK.
*
* At this point "configure" has already been called on the FIRApp instance. This behavior is meant to mirror
* what is done in ReactNativeFirebaseCrashlyticsInitProvider.java
*
* This pattern may not be supported long term https://github.com/firebase/firebase-ios-sdk/issues/2933
*/
+ (void)configureWithApp:(FIRApp *)app {
// This setting is sticky. setCrashlyticsCollectionEnabled persists the setting to disk until it is explicitly set otherwise or the app is deleted.
// Jump to the setCrashlyticsCollectionEnabled definition to see implementation details.
[[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:self.isCrashlyticsCollectionEnabled];
DLog(@"initialization successful");
}

@end

1 comment on commit cda4c10

@vercel
Copy link

@vercel vercel bot commented on cda4c10 Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.