Skip to content

Commit

Permalink
feat: update crashlytics setting
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Sep 6, 2024
1 parent e2c173d commit 6949b66
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 61 deletions.
23 changes: 23 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
C5C69C4274830CDFF1F48AE0 /* [CP] Embed Pods Frameworks */,
A48806D922AF5CC500608B9C /* ShellScript */,
7B52B608005F40B6BAE8AEF5 /* [CP] Copy Pods Resources */,
3343CD5A2182BD2E192F10F9 /* FlutterFire: "flutterfire upload-crashlytics-symbols" */,
);
buildRules = (
);
Expand Down Expand Up @@ -332,6 +333,24 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
3343CD5A2182BD2E192F10F9 /* FlutterFire: "flutterfire upload-crashlytics-symbols" */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "FlutterFire: \"flutterfire upload-crashlytics-symbols\"";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\n#!/bin/bash\nPATH=${PATH}:$FLUTTER_ROOT/bin:$HOME/.pub-cache/bin\nflutterfire upload-crashlytics-symbols --upload-symbols-script-path=$PODS_ROOT/FirebaseCrashlytics/upload-symbols --platform=ios --apple-project-path=${SRCROOT} --env-platform-name=${PLATFORM_NAME} --env-configuration=${CONFIGURATION} --env-project-dir=${PROJECT_DIR} --env-built-products-dir=${BUILT_PRODUCTS_DIR} --env-dwarf-dsym-folder-path=${DWARF_DSYM_FOLDER_PATH} --env-dwarf-dsym-file-name=${DWARF_DSYM_FILE_NAME} --env-infoplist-path=${INFOPLIST_PATH} --default-config=default\n";
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down Expand Up @@ -377,10 +396,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/firebase_messaging/firebase_messaging_Privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/google_sign_in_ios/google_sign_in_ios_privacy.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/firebase_messaging_Privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/google_sign_in_ios_privacy.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -455,6 +476,7 @@
"${BUILT_PRODUCTS_DIR}/FirebaseMessaging/FirebaseMessaging.framework",
"${BUILT_PRODUCTS_DIR}/FirebasePerformance/FirebasePerformance.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfig/FirebaseRemoteConfig.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfigInterop/FirebaseRemoteConfigInterop.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseSessions/FirebaseSessions.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseSharedSwift/FirebaseSharedSwift.framework",
"${BUILT_PRODUCTS_DIR}/GTMAppAuth/GTMAppAuth.framework",
Expand Down Expand Up @@ -497,6 +519,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseMessaging.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebasePerformance.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseRemoteConfig.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseRemoteConfigInterop.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseSessions.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseSharedSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMAppAuth.framework",
Expand Down
113 changes: 52 additions & 61 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,62 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
);
}

void main() {
runZonedGuarded(
() async {
WidgetsFlutterBinding.ensureInitialized();
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

final ByteData data = await PlatformAssetBundle().load(
'assets/ca/twca_nsysu.cer',
);
SecurityContext.defaultContext.setTrustedCertificatesBytes(
data.buffer.asUint8List(),
);
final ByteData data = await PlatformAssetBundle().load(
'assets/ca/twca_nsysu.cer',
);
SecurityContext.defaultContext.setTrustedCertificatesBytes(
data.buffer.asUint8List(),
);

await Preferences.init(
key: Constants.key,
iv: Constants.iv,
);
await Preferences.init(
key: Constants.key,
iv: Constants.iv,
);

timeago.setLocaleMessages('zh-TW', timeago.ZhMessages());
timeago.setLocaleMessages('en-US', timeago.EnMessages());
if (!kIsWeb && Platform.isAndroid) {
//TODO: 改使用原生方式限制特定網域
HttpOverrides.global = MyHttpOverrides();
}
final String currentVersion =
Preferences.getString(Constants.prefCurrentVersion, '0');
if (int.parse(currentVersion) < 700) _migrate700();
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler,
);
if (FirebaseUtils.isSupportCore ||
Platform.isWindows ||
Platform.isLinux) {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
}
if (kDebugMode) {
if (FirebaseCrashlyticsUtils.isSupported) {
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(false);
}
if (FirebasePerformancesUtils.isSupported) {
await FirebasePerformance.instance
.setPerformanceCollectionEnabled(false);
}
}
if (!kIsWeb &&
(Platform.isWindows || Platform.isMacOS || Platform.isLinux)) {
GoogleSignInDart.register(
clientId: SdkConstants.googleSignInDesktopClientId,
);
}
if (!kDebugMode && FirebaseCrashlyticsUtils.isSupported) {
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
}
runApp(MyApp());
},
(Object e, StackTrace s) {
if (!kDebugMode && FirebaseCrashlyticsUtils.isSupported) {
FirebaseCrashlytics.instance.recordError(e, s);
} else {
throw e;
}
},
timeago.setLocaleMessages('zh-TW', timeago.ZhMessages());
timeago.setLocaleMessages('en-US', timeago.EnMessages());
if (!kIsWeb && Platform.isAndroid) {
//TODO: 改使用原生方式限制特定網域
HttpOverrides.global = MyHttpOverrides();
}
final String currentVersion =
Preferences.getString(Constants.prefCurrentVersion, '0');
if (int.parse(currentVersion) < 700) _migrate700();
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler,
);
if (FirebaseUtils.isSupportCore || Platform.isWindows || Platform.isLinux) {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
}
if (kDebugMode) {
if (FirebaseCrashlyticsUtils.isSupported) {
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
}
if (FirebasePerformancesUtils.isSupported) {
await FirebasePerformance.instance.setPerformanceCollectionEnabled(false);
}
}
if (!kIsWeb && (Platform.isWindows || Platform.isMacOS || Platform.isLinux)) {
GoogleSignInDart.register(
clientId: SdkConstants.googleSignInDesktopClientId,
);
}

if (!kDebugMode && FirebaseCrashlyticsUtils.isSupported) {
FlutterError.onError = (FlutterErrorDetails errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
FirebaseCrashlytics.instance.recordError(error, stack);
return true;
};
}
runApp(MyApp());
}

void _migrate700() {
Expand Down

0 comments on commit 6949b66

Please sign in to comment.