Skip to content

Commit 7dea95b

Browse files
authored
feat: fcm 알림 약 복용 체크용 커스텀 액션 추가 (#177)
* feat: 약 복용 알림 기능 추가 * feat: fcm 알림 약 복용 체크용 커스텀 액션 추가
1 parent ae35ff7 commit 7dea95b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

frontend/ongi/lib/main.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
23
import 'package:intl/date_symbol_data_local.dart';
34
import 'package:ongi/screens/login/login_pw_screen.dart';
45
import 'package:ongi/screens/splash_screen.dart';
@@ -9,6 +10,8 @@ import 'package:firebase_core/firebase_core.dart';
910
import 'firebase_options.dart';
1011
import 'package:firebase_messaging/firebase_messaging.dart';
1112

13+
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
14+
1215
void main() async {
1316
WidgetsFlutterBinding.ensureInitialized();
1417
await initializeDateFormatting();
@@ -25,9 +28,38 @@ void main() async {
2528
provisional: false,
2629
sound: true,
2730
);
31+
32+
messaging.setForegroundNotificationPresentationOptions(
33+
alert: true, badge: true, sound: true,
34+
);
2835

2936
_initializeFCMIfLoggedIn();
3037

38+
const categoryId = 'PILL_TAKE_REMINDER';
39+
final iosInit = DarwinInitializationSettings(
40+
requestAlertPermission: true,
41+
requestBadgePermission: true,
42+
requestSoundPermission: true,
43+
notificationCategories: [
44+
DarwinNotificationCategory(
45+
categoryId,
46+
actions: [
47+
DarwinNotificationAction.plain('ACCEPT', '복용 완료!'),
48+
],
49+
),
50+
],
51+
);
52+
final initSettings = InitializationSettings(iOS: iosInit);
53+
await flutterLocalNotificationsPlugin.initialize(
54+
initSettings,
55+
onDidReceiveNotificationResponse: (resp) {
56+
switch (resp.actionId) {
57+
case 'ACCEPT':
58+
break;
59+
}
60+
}
61+
);
62+
3163
runApp(const OngiApp());
3264
}
3365

frontend/ongi/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies:
3232
geocoding: ^4.0.0
3333
image_picker: ^1.1.2
3434
url_launcher: ^6.2.1
35+
flutter_local_notifications: ^19.4.0
3536

3637
dev_dependencies:
3738
flutter_test:

0 commit comments

Comments
 (0)