Skip to content

Commit

Permalink
fix: #69 background 등록 main으로 수정, logger 삭제 , home view constarint수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwest00 committed Nov 24, 2023
1 parent c9d94e3 commit 87717ff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ Future<void> initService() async {
if (token != null) {
DioServices().setAccessToken(token);
}
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}

Future<void> _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 토큰 발급 코드
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/home/widget/home_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions lib/provider/api/auth_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class UserAuthApi {
">>> (애플로그인) 사용자의 accessToken: ${response.data[RESULT]["accessToken"]}");
String token = response.data[RESULT]["accessToken"];
DioServices().setAccessToken(token);

}

return true;
Expand Down Expand Up @@ -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]);
Expand Down
23 changes: 2 additions & 21 deletions lib/provider/service/fcm_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -162,25 +163,5 @@ class FcmService extends GetxService {
}
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}

@pragma('vm:entry-point')
Future<void> _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 ?? "");
}
}
}
}

0 comments on commit 87717ff

Please sign in to comment.