개요
앱에서 push notification을 사용하지 않아도 개발이 가능할 것 같아서 local notification으로 대체하려고 한다.
안드로이드, ios 환경에서 구동이 가능해야 하며 foreground, backgorund, terminated 상태에서도 notification이 가능해야 한다.
flutter_local_notifications | Flutter Package
flutter_local_notifications | Flutter Package
A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform.
pub.dev
flutter_local_notifiacations에서 해당 기능을 제공한다고 하여서 toy project를 생성하려고 한다.
참고자료
[Flutter] 로컬 푸시 노티피케이션
Flutter에서 flutter_local_notifications를 사용하여 기기 자체에서 특정 시간에 푸시 메시지를 표시하는 방법에 대해서 알아봅시다.
dev-yakuza.posstree.com
해당 블로그에서는 flutter_local_notifications, flutter_app_badger, flutter_native_timezone을 사용하여 local push notification을 보내는 예시코드를 설명하고 있습니다.
- 안드로이드에서는 permission이 필요하지 않음.
- push 알림을 누르면 특정 페이지로 이동하게 할 수 있음.
- 처음에 초기화하는 코드에서 이렇게 Permission들을 false로 한 이유는 나중에 permission을 받기 위함이다.
Future<void> _initializeNotification() async {
const IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
);
_requestPermissions라는 함수를 call해서 추후에 permission을 받게 했다.
Future<void> _requestPermissions() async {
await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}
- callback함수가 뭐였지?
https://www.geeksforgeeks.org/flutter-working-with-callback-functions/
Flutter - Working with Callback Functions - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org
Callback is basically a function or a method that we pass as an argument into another function or a method to perform an action. In the simplest words, we can say that Callback or VoidCallback are used while sending data from one method to another and vice-versa. It is very important to maintain a continuous flow of data throughout the flutter app.
결과
GitHub - growbook91/flutter_local_notifications_example
GitHub - growbook91/flutter_local_notifications_example
Contribute to growbook91/flutter_local_notifications_example development by creating an account on GitHub.
github.com
일단, pub.dev에 기재되어 있는 것처럼 flutter_local_notification을 사용하면 terminated 상태에서도 push 알림을 보낼 수 있었다.
'flutter' 카테고리의 다른 글
flutter에서 Inspector 사용하는 법 (1) | 2022.06.29 |
---|---|
특정화면에서 flutter를 실행하는 법 (0) | 2022.06.29 |
Firestore, android 연동 오류 (0) | 2022.06.27 |
Firebase Cloud Function (0) | 2022.06.27 |