fix:第一轮跑
This commit is contained in:
1 parent
e834ec7586
commit
33235f450b
56 files changed
+4357
-210
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../storage/storage_keys.dart';
|
||||
import '../storage/storage_service.dart';
|
||||
import '../widgets/notification_permission_tip.dart';
|
||||
|
||||
abstract final class NotificationPermission {
|
||||
static Future<bool> isGranted() async =>
|
||||
!kIsWeb && (await Permission.notification.status).isGranted;
|
||||
|
||||
/// 对齐研听:Android 13+ 由应用解释后主动申请;iOS 由 U-Push 注册 APNs
|
||||
/// 时触发系统授权,绝不展示 Android 的自定义顶部提示。
|
||||
static Future<bool> requestIfNeeded(BuildContext context) async {
|
||||
if (kIsWeb || defaultTargetPlatform != TargetPlatform.android) {
|
||||
return isGranted();
|
||||
}
|
||||
final android = await DeviceInfoPlugin().androidInfo;
|
||||
if (android.version.sdkInt < 33 ||
|
||||
StorageService.to.getBool(storagePushPermissionPrompted)) {
|
||||
return isGranted();
|
||||
}
|
||||
if (await isGranted() || !context.mounted) return true;
|
||||
await showNotificationPermissionTip(context);
|
||||
await StorageService.to.setBool(storagePushPermissionPrompted, true);
|
||||
return (await Permission.notification.request()).isGranted;
|
||||
}
|
||||
|
||||
/// 设置页不使用顶部说明;iOS/Android 都直接请求系统授权。
|
||||
static Future<bool> requestFromSettings() async {
|
||||
if (kIsWeb) return false;
|
||||
final current = await Permission.notification.status;
|
||||
if (current.isGranted) return true;
|
||||
await StorageService.to.setBool(storagePushPermissionPrompted, true);
|
||||
return (await Permission.notification.request()).isGranted;
|
||||
}
|
||||
|
||||
static Future<bool> openSystemSettings() => openAppSettings();
|
||||
}
|
||||
Reference in new issue
Block a user