You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Flutter应用实现版本更新推送通知,引导用户更新iOS/Android应用

iOS平台引导用户前往App Store更新应用的实现

核心流程:版本检测 → 更新提示 → 跳转商店

  1. 获取本地应用版本
    同样使用package_info_plus包,代码与Android端一致。

  2. 获取App Store最新版本
    调用苹果官方iTunes Search API获取最新版本:

import 'package:http/http.dart' as http;
import 'dart:convert';

Future<String> getLatestiOSAppVersion(String bundleId) async {
  final response = await http.get(Uri.parse('https://itunes.apple.com/lookup?bundleId=$bundleId'));
  if (response.statusCode == 200) {
    final jsonData = jsonDecode(response.body);
    if (jsonData['resultCount'] > 0) {
      return jsonData['results'][0]['version'];
    }
  }
  throw Exception('无法获取最新版本信息');
}
  1. 版本对比
    使用version包的版本比较逻辑,与Android端一致。

  2. 触发更新提示与跳转
    弹窗引导用户跳转App Store,iOS使用itms-apps://协议直接唤起App Store:

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void showAppStoreUpdateDialog(BuildContext context) {
  showDialog(
    context: context,
    barrierDismissible: false,
    builder: (_) => AlertDialog(
      title: const Text('发现新版本'),
      content: const Text('应用已更新至1.0.1版本,立即下载更新获取新功能和优化。'),
      actions: [
        TextButton(
          onPressed: () => Navigator.pop(context),
          child: const Text('稍后更新'),
        ),
        ElevatedButton(
          onPressed: () async {
            const appStoreLink = 'itms-apps://itunes.apple.com/app/id=你的应用ID';
            if (await canLaunchUrl(Uri.parse(appStoreLink))) {
              await launchUrl(Uri.parse(appStoreLink));
            }
            Navigator.pop(context);
          },
          child: const Text('立即更新'),
        ),
      ],
    ),
  );
}

额外提示

  • 版本检测时机:建议在APP启动时执行,避免干扰用户操作;
  • 强制更新场景:若需用户必须更新才能使用,可隐藏“稍后更新”按钮,弹窗仅保留“立即更新”选项;
  • iOS后台限制:iOS不允许频繁后台检测版本,推荐仅在APP前台启动时检测。

内容的提问来源于stack exchange,提问作者Xavier Soh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 03:15:35