处理IOS没有升级弹窗问题

This commit is contained in:
豌杂 2025-03-17 13:56:11 +08:00
parent db01a953c2
commit 3919978c02
5 changed files with 95 additions and 48 deletions

View File

@ -44,10 +44,13 @@ class AppVersion extends Object {
this.appFileUrl,
this.description,
) {
if (appFileUrl != null) appFileUrl = RequestConfig.imgUrl + appFileUrl!;
if (appFileUrl != null && ftuType != 2) {
appFileUrl = RequestConfig.imgUrl + appFileUrl!;
}
}
factory AppVersion.fromJson(Map<String, dynamic> srcJson) => _$AppVersionFromJson(srcJson);
factory AppVersion.fromJson(Map<String, dynamic> srcJson) =>
_$AppVersionFromJson(srcJson);
Map<String, dynamic> toJson() => _$AppVersionToJson(this);
}

View File

@ -21,7 +21,8 @@ import 'upgradeLogic.dart';
class DownloadApk {
///
static Future<File?> _downloadAndroid(context, UpdateAppEvent event, UpgradeLogic logic) async {
static Future<File?> _downloadAndroid(
context, UpdateAppEvent event, UpgradeLogic logic) async {
///
Directory? storageDir = await getExternalStorageDirectory();
final storagePath = storageDir?.path ?? '/';
@ -47,10 +48,12 @@ class DownloadApk {
print(e);
// toPrint(val: e);
}
return null;
}
// apk
static Future<bool> installApk(context, UpdateAppEvent event, UpgradeLogic logic) async {
static Future<bool> installApk(
context, UpdateAppEvent event, UpgradeLogic logic) async {
try {
logic.loadingApk.value = true;
File? _apkFile = await _downloadAndroid(context, event, logic);
@ -73,7 +76,9 @@ class DownloadApk {
actions: [
MaterialButton(
color: Theme.of(context).primaryColor,
child: const Text("我已知晓", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
child: const Text("我已知晓",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
onPressed: () => Navigator.of(context).pop(),
),
],
@ -87,9 +92,12 @@ class DownloadApk {
//
// await SystemNavigator.pop(); // 退APP
var options = ['应用市场更新APP', '浏览器下载并安装APP'];
var uri = Uri.parse('market://details?id=${event.packageName}'); // URI
if (!await canLaunchUrl(uri)) options.removeAt(0); //
String? option = await UpgradePermission.showCustomModalBottomSheet(context, options);
var uri =
Uri.parse('market://details?id=${event.packageName}'); // URI
if (!await canLaunchUrl(uri))
options.removeAt(0); //
String? option = await UpgradePermission.showCustomModalBottomSheet(
context, options);
if (option == '应用市场更新APP') await launchUrl(uri);
if (option == '浏览器下载并安装APP') await launchUrl(Uri.parse(event.link));
} catch (_) {}
@ -107,7 +115,8 @@ class DownloadApk {
}
///
static void showDownloadProgress(context, num received, num total, UpgradeLogic logic) {
static void showDownloadProgress(
context, num received, num total, UpgradeLogic logic) {
if (total != -1) {
double progress = double.parse((received / total).toStringAsFixed(2));
// debugPrint('下载进度$progress');
@ -122,7 +131,8 @@ class RestartWidget extends StatefulWidget {
const RestartWidget({super.key, required this.child});
static restartApp(BuildContext context) {
final _RestartWidgetState? state = context.findAncestorStateOfType<_RestartWidgetState>();
final _RestartWidgetState? state =
context.findAncestorStateOfType<_RestartWidgetState>();
state?.restartApp();
}

View File

@ -14,7 +14,6 @@
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-01-12 15:08:43
*/
import 'package:auto_updater/auto_updater.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/utils/app_upgrade/DownloadApk.dart';
@ -34,7 +33,8 @@ class UpdateDialog extends Dialog {
final UpdateAppEvent updateAppEvent;
final String deviceInfo;
const UpdateDialog({super.key, required this.updateAppEvent, required this.deviceInfo});
const UpdateDialog(
{super.key, required this.updateAppEvent, required this.deviceInfo});
@override
Widget build(BuildContext context) {
@ -72,11 +72,17 @@ class UpdateDialog extends Dialog {
HtmlWidget(
updateAppEvent.description,
customStylesBuilder: (element) {
return {'color': '#666666', 'font-weight': 'normal', 'text-decoration': 'none'};
return {
'color': '#666666',
'font-weight': 'normal',
'text-decoration': 'none'
};
},
onLoadingBuilder: (context, element, loadingProgress) => const CircularProgressIndicator(),
onLoadingBuilder: (context, element, loadingProgress) =>
const CircularProgressIndicator(),
renderMode: RenderMode.column,
textStyle: TextStyle(fontSize: 14.sp, color: Colors.black87),
textStyle:
TextStyle(fontSize: 14.sp, color: Colors.black87),
)
],
),
@ -97,7 +103,9 @@ class UpdateDialog extends Dialog {
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: UpdateDialog(updateAppEvent: updateAppEvent, deviceInfo: updateAppEvent.deviceInfo),
child: UpdateDialog(
updateAppEvent: updateAppEvent,
deviceInfo: updateAppEvent.deviceInfo),
);
},
);
@ -136,7 +144,10 @@ class DownloadProgress extends StatelessWidget {
Container(
height: 6.h,
),
quickText('更新中...', size: 12.sp, fontWeight: FontWeight.w500, color: const Color.fromRGBO(90, 90, 90, 1))
quickText('更新中...',
size: 12.sp,
fontWeight: FontWeight.w500,
color: const Color.fromRGBO(90, 90, 90, 1))
],
);
});
@ -152,7 +163,7 @@ class DownloadButton extends StatelessWidget {
//
Future<bool> toLaunch(UpdateAppEvent data) async {
var uri = Uri.parse('market://details?id=com.yuanxuan.making_school_asignment_app');
var uri = Uri.parse('market://details?id=${updateAppEvent.packageName}');
if (await canLaunchUrl(uri)) {
//
return await launchUrl(uri);
@ -181,15 +192,20 @@ class DownloadButton extends StatelessWidget {
width: 245.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(42.h)),
gradient: LinearGradient(colors: [primaryColor, primaryColor.withOpacity(0.7)]),
gradient: LinearGradient(
colors: [primaryColor, primaryColor.withOpacity(0.7)]),
),
child: MaterialButton(
onPressed: () => easyThrottle('DownloadButton_App_Upgrade', duration: const Duration(milliseconds: 1000), () async {
if (deviceInfo == "android" && updateAppEvent.equipment == Equipment.android) {
onPressed: () => easyThrottle('DownloadButton_App_Upgrade',
duration: const Duration(milliseconds: 1000), () async {
if (deviceInfo == "android" &&
updateAppEvent.equipment == Equipment.android) {
//
bool flag = await UpgradePermission(updateAppEvent.deviceInfo).checkPermission(context, updateAppEvent);
bool flag = await UpgradePermission(updateAppEvent.deviceInfo)
.checkPermission(context, updateAppEvent);
if (flag) {
flag = await DownloadApk.installApk(context, updateAppEvent, logic);
flag = await DownloadApk.installApk(
context, updateAppEvent, logic);
if (!flag) {
print('执行到了重置更新按钮的地方....');
logic.downloadRatio.value = 0.0; //
@ -201,8 +217,10 @@ class DownloadButton extends StatelessWidget {
}
// await FlutterClipboard.copy(updateAppEvent.link);
// setTimeOut(1000, () => ToastUtils.showInfo('下载链接已经复制到设备,可前往浏览器下载安装'));
} else if (deviceInfo == "ios" && updateAppEvent.equipment == Equipment.ios) {
} else if (deviceInfo == "ios" &&
updateAppEvent.equipment == Equipment.ios) {
try {
print(updateAppEvent.link);
await launchUrlString(updateAppEvent.link);
} catch (e) {
print('进来更新报错$e');
@ -214,7 +232,8 @@ class DownloadButton extends StatelessWidget {
// await autoUpdater.setScheduledCheckInterval(0);
// }
}),
child: quickText(!logic.loadingApk.value ? '立即体验' : '正在下载...', size: 16.sp, color: Colors.white, fontWeight: FontWeight.w500),
child: quickText(!logic.loadingApk.value ? '立即体验' : '正在下载...',
size: 16.sp, color: Colors.white, fontWeight: FontWeight.w500),
),
);
});

View File

@ -44,7 +44,8 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
return;
}
AppVersion? result = await getClient().getLastAppVersion('making_school_asignment_app', deviceType);
AppVersion? result = await getClient()
.getLastAppVersion('making_school_asignment_app', deviceType);
if (result != null) {
//
PackageInfo packageInfo = await PackageInfo.fromPlatform();
@ -60,8 +61,11 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
'systemType': deviceType,
'description': result.description ?? 'APP新版本更新'
};
UpdateAppEvent updateAppEvent = UpdateAppEvent.fromJson(json, localVersion, deviceInfo, appName, packageName, typeName: 'systemType');
UpdateAppEvent updateAppEvent = UpdateAppEvent.fromJson(
json, localVersion, deviceInfo, appName, packageName,
typeName: 'systemType');
if (updateAppEvent.upgrade) {
if (Platform.isAndroid) {
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
Permission storagePermission;
@ -70,13 +74,18 @@ class UpgradeLogic extends GetxController with RequestToolMixin {
} else {
storagePermission = Permission.storage;
}
PermissionDescribeUtil.instance.toLaunchPermissionRequest(
context,
await PermissionDescribeUtil.instance.toLaunchPermissionRequest(
Get.context ?? context,
title: '储存权限请求',
describe: "为了提供更好的服务需要获取到存储权限用于保存APP升级文件APK进行升级",
permissions: [storagePermission],
);
await UpdateDialog.showUpdateDialog(context, updateAppEvent);
}
await UpdateDialog.showUpdateDialog(
Get.context ?? context,
updateAppEvent,
);
}
}
} finally {

View File

@ -12,13 +12,18 @@ class PermissionDescribePage extends StatefulWidget {
final String describe;
final List<Permission> permissions;
const PermissionDescribePage({required this.title, required this.describe, required this.permissions, super.key});
const PermissionDescribePage(
{required this.title,
required this.describe,
required this.permissions,
super.key});
@override
State<PermissionDescribePage> createState() => _PermissionDescribePageState();
}
class _PermissionDescribePageState extends State<PermissionDescribePage> with WidgetsBindingObserver {
class _PermissionDescribePageState extends State<PermissionDescribePage>
with WidgetsBindingObserver {
Timer? _timerPermission;
bool theOpenAppSettings = false;
int theExecutionFrequency = 0;
@ -132,7 +137,9 @@ class _PermissionDescribePageState extends State<PermissionDescribePage> with Wi
///
/// @param List<Permission> permissions
Future<List<Permission>> getStoragePermission(BuildContext context, List<Permission> permissions, [int executionFrequency = 0]) async {
Future<List<Permission>> getStoragePermission(
BuildContext context, List<Permission> permissions,
[int executionFrequency = 0]) async {
Map<Permission, PermissionStatus> statusRes = await permissions.request();
List<Permission> permanentRefusal = []; //
@ -173,7 +180,8 @@ class _PermissionDescribePageState extends State<PermissionDescribePage> with Wi
executionFrequency++;
}
if (executionFrequency <= 1) {
var res = await getStoragePermission(context, [key], executionFrequency);
var res =
await getStoragePermission(context, [key], executionFrequency);
permanentRefusal.addAll(res);
} else {
permanentRefusal.add(key);
@ -231,12 +239,10 @@ class PermissionDescribeUtil {
PermissionDescribeUtil._internal();
static get instance {
return _instance ??= PermissionDescribeUtil._internal();
}
static get instance => _instance ??= PermissionDescribeUtil._internal();
///
void toLaunchPermissionRequest(
Future<void> toLaunchPermissionRequest(
BuildContext context, {
required String title,
required String describe,