From 87717ff3740d40c2be502ada26223f43d6c71d41 Mon Sep 17 00:00:00 2001 From: kimwest00 Date: Fri, 24 Nov 2023 13:26:34 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20#69=20background=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?main=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95,=20logger=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20,=20home=20view=20constarint=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 13 +++++++++++++ lib/modules/home/widget/home_widget.dart | 4 ++-- lib/provider/api/auth_api.dart | 3 +-- lib/provider/service/fcm_service.dart | 23 ++--------------------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 300a032e..88b4c143 100755 --- a/lib/main.dart +++ b/lib/main.dart @@ -60,6 +60,19 @@ Future initService() async { if (token != null) { DioServices().setAccessToken(token); } + FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); +} + +Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { + await Firebase.initializeApp(); + print("Handling a background message: ${message.messageId}"); + if (message.notification != null) { + logger.d(message.notification!.title); + logger.d(message.notification!.body); + FcmService.showNotification( + title: message.notification!.title ?? "", + content: message.notification!.body ?? ""); + } } // 알림권한 관련 APNS 토큰 발급 코드 diff --git a/lib/modules/home/widget/home_widget.dart b/lib/modules/home/widget/home_widget.dart index 2df439c9..2a3cacb0 100644 --- a/lib/modules/home/widget/home_widget.dart +++ b/lib/modules/home/widget/home_widget.dart @@ -202,8 +202,8 @@ class FlameWidget extends StatelessWidget { ? Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox( - width: 200.w, + Container( + constraints: BoxConstraints(maxWidth: 200.w), child: Text( flameName!.substring(0, flameName!.length - 3), style: AppTextStyles.T1Bold18, diff --git a/lib/provider/api/auth_api.dart b/lib/provider/api/auth_api.dart index ba983b50..4293f840 100644 --- a/lib/provider/api/auth_api.dart +++ b/lib/provider/api/auth_api.dart @@ -85,7 +85,6 @@ class UserAuthApi { ">>> (애플로그인) 사용자의 accessToken: ${response.data[RESULT]["accessToken"]}"); String token = response.data[RESULT]["accessToken"]; DioServices().setAccessToken(token); - } return true; @@ -170,7 +169,7 @@ class UserAuthApi { timeInSecForIosWeb: 1); logger.e(response.data[CODE]); } - logger.e(response.data[RESULT]); + // logger.e(response.data[RESULT]); logger.i( '>>> 로그인 성공 후 사용자의 accessToken: ${response.data[RESULT]["accessToken"]}'); saveToken(response.data[RESULT]); diff --git a/lib/provider/service/fcm_service.dart b/lib/provider/service/fcm_service.dart index dc5cb7d4..7aaf8def 100644 --- a/lib/provider/service/fcm_service.dart +++ b/lib/provider/service/fcm_service.dart @@ -20,6 +20,7 @@ class FcmService extends GetxService { @override void onInit() async { super.onInit(); + logger.d("fcm init"); AndroidInitializationSettings androidInitializationSettings = const AndroidInitializationSettings('drawable/splash'); DarwinInitializationSettings iosInitializationSettings = @@ -126,7 +127,7 @@ class FcmService extends GetxService { fcmToken: fcmToken ?? "", deviceId: deviceId); logger.d(tmpResult); } - + await setupInteractedMessage(); await FirebaseMessaging.instance.setAutoInitEnabled(true); FirebaseMessaging.instance.onTokenRefresh.listen((token) async { logger.w("!!!refreseh Token: $token"); @@ -162,25 +163,5 @@ class FcmService extends GetxService { } } }); - FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); - } - - @pragma('vm:entry-point') - Future _firebaseMessagingBackgroundHandler( - RemoteMessage? message) async { - // If you're going to use other Firebase services in the background, such as Firestore, - // make sure you call `initializeApp` before using other Firebase services. - await Firebase.initializeApp(); - - logger.w("!!!Handling a background message: ${message?.messageId}"); - if (message != null) { - if (message.notification != null) { - logger.d(message.notification!.title); - logger.d(message.notification!.body); - FcmService.showNotification( - title: message.notification!.title ?? "", - content: message.notification!.body ?? ""); - } - } } }