본문 바로가기
카테고리 없음

flutter_local_notifications(2/2)

by dev_caleb 2022. 7. 20.
728x90

Full-screen intent notifications 

If your application needs the ability to schedule full-screen intent notifications, add the following attributes to the activity you're opening. For a Flutter application, there is typically only one activity extends from FlutterActivity. These attributes ensure the screen turns on and shows when the device is locked.

 

프로그램에서 전체 화면 intent 알림을 예약해야 하는 경우 당신이 열고 있는 activity에 다음 속성을 추가하십시오. Flutter 애플리케이션의 경우 Flatter Activity로부터 extends 되는 activity은 일반적으로 하나만 있습니다. 이러한 속성은 장치가 잠겼을 때 화면을 키고  표시되도록 보장합니다.

 

<activity
    android:showWhenLocked="true"
    android:turnScreenOn="true">

 

For reference, the example app's AndroidManifest.xml file can be found here.

 

Note that when a full-screen intent notification actually occurs (as opposed to a heads-up notification that the system may decide should occur), the plugin will act as though the user has tapped on a notification so handle those the same way (e.g. onSelectNotification callback) to display the appropriate page for your application.

 

note that a full-screen intent notification이 실질적으로 일어났을 때,(시스템이 발생해야 한다고 결정할 수 있는 경고 통지와는 반대로), 플러그인은 사용자가 알림을 누른 것처럼 작동하므로 애플리케이션에 적합한 페이지를 표시하기 위해 동일한 방식으로(예: 알림 콜백 선택) 처리합니다.

 

Release build configuration (빌드 구성 배포)

Before creating the release build of your app (which is the default setting when building an APK or app bundle) you will need to customise your ProGuard configuration file as per this link. Rules specific to the GSON dependency being used by the plugin will need to be added. These rules can be found here. Whilst the example app has a Proguard rules (proguard-rules.pro) here, it is recommended that developers refer to the rules on the GSON repository in case they get updated over time.

앱의 배포 빌드(APK 또는 앱 번들을 빌드할 때의 기본 설정)를 만들기 전에 이 링크에 따라 ProGuard 구성 파일을 사용자 지정해야 합니다. 플러그인이 사용 중인 GSON 종속성 관련 규칙을 추가해야 합니다. 이러한 규칙은 여기에서 확인할 수 있습니다. 예제 앱에는 여기에 Proguard 규칙(proguard-rules.pro)이 있지만, 시간이 지남에 따라 업데이트되는 경우 개발자는 GSON 저장소의 규칙을 참조하는 것이 좋습니다.

 

⚠️ Ensure that you have configured the resources that should be kept so that resources like your notification icons aren't discarded by the R8 compiler by following the instructions here. If you fail to do this, notifications might be broken. In the worst case they will never show, instead silently failing when the system looks for a resource that has been removed. If they do still show, you might not see the icon you specified. The configuration used by the example app can be found here where it is specifying that all drawable resources should be kept, as well as the file used to play a custom notification sound (sound file is located here).

R8 컴파일러에 의해 알림 아이콘과 같은 리소스가 삭제되지 않도록 보관해야 하는 리소스를 구성했는지 확인하십시오. 이렇게 하지 않으면 알림이 깨질 수 있습니다. 최악의 경우 시스템이 제거된 리소스를 찾을 때 자동으로 실패합니다. 계속 표시되는 경우 지정한 아이콘이 표시되지 않을 수 있습니다. 예제 앱에서 사용하는 구성은 사용자 지정 알림 소리를 재생하는 데 사용되는 파일(사운드 파일이 여기에 있음)뿐만 아니라 모든 그리기 가능한 리소스를 보관하도록 지정하는 여기에서 찾을 수 있습니다.

 

//중간은 딱히 필요 없는 부분인 듯

 

❓ Usage 

Before going on to copy-paste the code snippets in this section, double-check you have configured your application correctly. If you encounter any issues please refer to the API docs and the sample code in the example directory before opening a request on Github.

이 섹션의 코드 스니펫을 복사하여 붙여넣기 전에 응용 프로그램이 올바르게 구성되었는지 다시 확인하십시오. 문제가 발생하면 Github에서 요청을 열기 전에 예제 디렉터리의 API 문서 및 샘플 코드를 참조하십시오.

 

Example app 

The example directory has a sample application that demonstrates the features of this plugin.

예제 디렉터리에는 이 플러그인의 기능을 보여주는 샘플 응용 프로그램이 있습니다.

API reference 

Checkout the lovely API documentation generated by pub.

pub에서 생성한 사랑스러운 API 문서를 확인하십시오.

Initialisation (초기화)

The first step is to create a new instance of the plugin class and then initialise it with the settings to use for each platform
첫 번째 단계는 플러그인 클래스의 새 인스턴스를 만든 다음 각 플랫폼에 사용할 설정으로 초기화하는 것입니다.

 

 

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
const AndroidInitializationSettings initializationSettingsAndroid =
    AndroidInitializationSettings('app_icon');
final IOSInitializationSettings initializationSettingsIOS =
    IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
final MacOSInitializationSettings initializationSettingsMacOS =
    MacOSInitializationSettings();
final InitializationSettings initializationSettings = InitializationSettings(
    android: initializationSettingsAndroid,
    iOS: initializationSettingsIOS,
    macOS: initializationSettingsMacOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
    onSelectNotification: selectNotification);

Initialisation can be done in the main function of your application or can be done within the first page shown in your app. Developers can refer to the example app that has code for the initialising within the mainfunction.

Initialisation는 응용 프로그램의 주요 기능에서 수행하거나 응용 프로그램에 표시된 첫 페이지 내에서 수행할 수 있습니다. 개발자들은 메인 기능 내에 초기화 코드가 있는 예시 앱을 참조할 수 있다.

 

The code above has been simplified for explaining the concepts. Here we have specified the default icon to use for notifications on Android (refer to the Android setup section) and designated the function (selectNotification) that should fire when a notification has been tapped on via the onSelectNotification callback.

위의 코드는 개념을 설명하기 위해 단순화되었다. 여기에서는 Android에서 알림에 사용할 기본 아이콘을 지정하고(Android 설정 섹션 참조), onSelectNotification 콜백을 통해 알림을 눌렀을 때 발생하는 기능(알림 선택)을 지정했습니다.

 

Specifying this callback is entirely optional but here it will trigger navigation to another page and display the payload associated with the notification. Also note that since version 4.0 of the plugin, this callback cannot be used to handle when a notification launched an app.

이 콜백을 지정하는 것은 전적으로 선택 사항이지만, 여기서 다른 페이지로 이동하여 알림과 관련된 페이로드를 표시합니다. 또한 플러그인 버전 4.0부터는 알림이 앱을 시작할 때 이 콜백을 사용하여 처리할 수 없습니다.

 

Use the getNotificationAppLaunchDetails method when the app starts if you need to handle when a notification triggering the launch for an app e.g. change the home route of the app for deep-linking.

앱 실행을 트리거하는 알림이 딥링크를 위해 앱의 홈 경로를 변경하는 등 처리해야 하는 경우 앱이 시작될 때 getNotificationAppLaunchDetails 메서드를 사용합니다.

 

Note that all settings are nullable, because we don't want to force developers so specify settings for platforms they don't target. You will get a runtime ArgumentError Exception if you forgot to pass the settings for the platform you target.

개발자가 대상으로 하지 않는 플랫폼에 대한 설정을 지정하도록 강요하고 싶지 않기 때문에 모든 설정은  nullable이다. 대상 플랫폼에 대한 설정을 전달하지 않은 경우 런타임 인수 오류 예외가 발생합니다.

 

 

 

 

728x90