Showing
1 changed file
with
27 additions
and
0 deletions
| @@ -140,6 +140,8 @@ class TodayController extends GetMaterialController { | @@ -140,6 +140,8 @@ class TodayController extends GetMaterialController { | ||
| 140 | 'enter_doublefeel_today_status', | 140 | 'enter_doublefeel_today_status', |
| 141 | properties: {'user_role': isFriend ? '好友的' : '我的'}, | 141 | properties: {'user_role': isFriend ? '好友的' : '我的'}, |
| 142 | ); | 142 | ); |
| 143 | + // 如果没有通知权限, 这里请求一下权限 | ||
| 144 | + _requestNotificationAuthorizationIfNeeded(); | ||
| 143 | } | 145 | } |
| 144 | 146 | ||
| 145 | @override | 147 | @override |
| @@ -184,6 +186,31 @@ class TodayController extends GetMaterialController { | @@ -184,6 +186,31 @@ class TodayController extends GetMaterialController { | ||
| 184 | }); | 186 | }); |
| 185 | } | 187 | } |
| 186 | 188 | ||
| 189 | + Future<void> _requestNotificationAuthorizationIfNeeded() async { | ||
| 190 | + try { | ||
| 191 | + final status = await Permission.notification.status; | ||
| 192 | + | ||
| 193 | + if (status.isGranted) { | ||
| 194 | + // 已授权,无需再请求 | ||
| 195 | + return; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + if (status.isPermanentlyDenied) { | ||
| 199 | + // 用户永久拒绝(Android),引导去设置 | ||
| 200 | + await openAppSettings(); | ||
| 201 | + return; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + // 未决定 → 弹出系统授权弹窗 | ||
| 205 | + final result = await Permission.notification.request(); | ||
| 206 | + AppLogger.d(result.isGranted | ||
| 207 | + ? 'Notification authorization granted' | ||
| 208 | + : 'Notification authorization skipped'); | ||
| 209 | + } catch (error) { | ||
| 210 | + AppLogger.e('Notification authorization failed: $error'); | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + | ||
| 187 | Future<void> checkHrvAdBannerVisible() async { | 214 | Future<void> checkHrvAdBannerVisible() async { |
| 188 | if (isFriend) { | 215 | if (isFriend) { |
| 189 | showHrvAdBanner.value = false; | 216 | showHrvAdBanner.value = false; |
-
mentioned in commit 68ce9cb9
-
Please register or login to post a comment