Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Change ask permission for user-notification timing. #296

Conversation

keiji
Copy link
Collaborator

@keiji keiji commented Jul 28, 2021

Add logging on user-notification process.

Issue 番号 / Issue ID

目的 / Purpose

通知チャンネルの登録(Android)と、ローカル通知の許諾(iOS)のタイミングがアプリ起動時だと、初回起動時、利用規約に合意していないユーザーからは気が早く見えてしまうので、ホーム画面を表示したタイミングに変更した。

破壊的変更をもたらしますか / Does this introduce a breaking change?

[x] Yes
[ ] No

Pull Request の種類 / Pull Request type

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

検証方法 / How to test

コードの入手 / Get the code

git clone [repo-address]
cd [repo-name]
gh pr checkout 296
dotnet restore

コードの検証 / Test the code


確認事項 / What to check

  • ログの取得内容(これはdevelopブランチへのPR時にcocoa-devに見てもらった方がよさそう)

その他 / Other information

Add logging on user-notification process.
@keiji keiji requested a review from kazuhiro4949 July 28, 2021 10:22
@keiji keiji self-assigned this Jul 28, 2021
namespace Covid19Radar.Services
{
public interface ILocalNotificationService
{
public void ShowExposureNotification();
public Task PrepareAsync();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

準備用のメソッドを追加

public void ShowExposureNotification();
public Task PrepareAsync();

public Task ShowExposureNotificationAsync();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncを前提として、慣例としてメソッド名の末尾にAsyncを付ける。

{
base.OnAppearing();

await localNotificationService.PrepareAsync();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

表示されたタイミングで通知チャンネルの登録と許諾を得る。

OnAppearingがどういう条件で呼ばれるのかは確認したい。OnResumeは別にあるのでOnStartOnCreateくらいの頻度だと思うものの、あまり頻繁に呼ばれる場合はログの書き込みが多くなりすぎる可能性がある。

Copy link
Collaborator

@kazuhiro4949 kazuhiro4949 Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOSの場合viewDidAppearのタイミングで、画面遷移もしくは初回の画面生成時にHomePageが表示されたら呼ばれています。

Prismで定義されているようですが、実装を読むとXamarin.FormのOnAppearingのイベントにbindingしているだけのように見えるのでxamarinのOnAppearingがそうなっているようです。
https://github.com/PrismLibrary/Prism/blob/master/src/Forms/Prism.Forms/Behaviors/PageLifeCycleAwareBehavior.cs#L13

一方でOnResumeはApplicationのライフサイクルのもののようで、iOSだとバックグラウンドからの復帰で呼ばれます。逆に画面の表示タイミングで呼ばれることはないです。
https://github.com/PrismLibrary/Prism/blob/master/src/Forms/Prism.Forms/PrismApplicationBase.cs#L221

画面生成時のみ表示させたいという場合はInitializeになりそうです。(iOSだとviewDidLoadっぽい)
ENの開始はこのタイミングのようですね。
https://github.com/cocoa-mhlw/cocoa/pull/296/files#diff-0a52fc58c3dfa8eff5b2cb4952766ea63e70fa808d249be88a30edeb0785e7c1L66

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keiji ログの出力の頻度ってどのくらいが理想っていうのはありますか?↑の調査の通り、iOSの場合画面を切り替えてHomePageが表示されるたびにOnAppearingが呼ばれるようになっています

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ユーザーのストレージに蓄積するものなので、必要最小限が理想です。
そういう意味では、画面が表示される度に不要な処理が走る現在のPullRequestはよろしくありませんので、Initializeに移動します。

_loggerService = loggerService;
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncキーワードを使っているメソッドでawaitしていないために表示される警告を抑制する。

@keiji keiji marked this pull request as ready for review July 28, 2021 10:28
@kazuhiro4949
Copy link
Collaborator

コード的には問題なさそうです

@kazuhiro4949
Copy link
Collaborator

iOSアプリで最初のチュートリアル時にENの許諾を後回しにしてHomePageViewModelを開いた場合、
InitializeでのENのスタートのタイミングでEN許諾が表示され、同時にローカル通知の許諾が表示されるようになっていました。

許諾アラートは連続で呼ばれてもうまいこと表示されるようになっているので基本的には問題ないかなと思います。動作確認しても大丈夫そうでした。

ただちょっとiOS14でのテストしかしていないのでこれはマージしつつ、後で動作確認を行っておきます。また、順番をちゃんと制御できそうであればちょっと実装考えてみます。

@@ -9,7 +9,6 @@
using Covid19Radar.Services.Logs;
using DryIoc;
using Foundation;
using UserNotifications;
Copy link
Collaborator

@kazuhiro4949 kazuhiro4949 Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別のプルリクにて、AppDelegate内でUserNotificationsを使用する予定になったので削除しないでいただけると嬉しいですmm

#297

@keiji keiji requested a review from kazuhiro4949 July 28, 2021 16:54
@kazuhiro4949 kazuhiro4949 merged commit 48e25d2 into cocoa-mhlw:feature/local_notification Jul 29, 2021
@keiji keiji deleted the feature/local_notification_initialize branch July 29, 2021 08:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants