DEV Community

Cover image for Native iOS App Updater in Flutter: How Zomato, Swiggy, and Others Do It
Md. Mobin
Md. Mobin

Posted on

Native iOS App Updater in Flutter: How Zomato, Swiggy, and Others Do It

After a long break, we're back—because let's face it, as developers, the work never really stops. Today, we're talking about something we all deal with but don't always talk about: app updates. You know, those little notifications that users often ignore, but we desperately want them to notice.

You've been there—you build an awesome app, push new features, fix bugs... and then just hope users update. But what if they didn’t have to go to the App Store or Play Store to do it manually?

Some of the biggest apps, like Zomato and Swiggy, manage to keep things updated without users having to do anything. It’s not magic, though—it’s all about native app updaters, and if you’re using Flutter for iOS, it’s easier than you might think.

Let’s dive into how it works and how you can do it too.

Table of content

Introduction

Updating apps is a bit like flossing—something everyone knows should be done, but most users put off until it’s absolutely necessary. For developers, this can be frustrating. New features are rolled out, bugs are fixed, and the app runs smoother than ever, yet a large chunk of users are still on outdated versions.

In the world of Flutter development, Android makes automated updates a breeze. But iOS? That’s a different story. iOS tends to make things a bit more complicated, requiring extra effort to ensure users get the latest version of the app.

Fortunately, apps like Zomato, Swiggy and other apps have cracked the code, delivering seamless updates without users having to manually visit the App Store. And the good news? Native iOS app updaters in Flutter make it possible to do the same. Ready to see how? Let’s get started!

ios-app-updator-force-meme

App Updates on Android

Before diving into the coding and technical aspects, let’s discuss how to update a Flutter app—or even force an update—without making users leave the app.

Fortunately, Google provides the In-App Updates toolkit. This handy tool opens a native interface for downloading app updates right within the app itself. It handles everything from force updates to optional updates, making the process seamless for users. Plus, it takes care of managing the state after an update, ensuring a smooth transition to the latest version without any hiccups.

in_app_update_android

How to Integrate In-App Updates into Flutter

To integrate in-app updates in Flutter, you can use the in_app_update package for handling Android updates.

Steps

  1. Add the package to your pubspec.yaml:

    in_app_update:<latest_version>
    

Or run the following command:
flutter pub add in_app_update

  • Check for updates:
Future<void> checkForUpdate() async {
  InAppUpdate.checkForUpdate().then((info) {
    setState(() {
      _updateInfo = info;
    });
  }).catchError((e) {
    // Handle error
  });
}

Enter fullscreen mode Exit fullscreen mode
  • Download the Updated App:
Future<void> downloadUpdatedApp() {
  if (_updateInfo?.updateAvailability == UpdateAvailability.updateAvailable) {
    InAppUpdate.performImmediateUpdate()
        .catchError((e) {
          showSnack(e.toString());
          return AppUpdateResult.inAppUpdateFailed;
        });
  }
}
Enter fullscreen mode Exit fullscreen mode

For more details, check out the example

Challenges with App Updates on iOS

As we know, iOS has strict policies and guidelines regarding user experience, making it challenging to implement force updates for apps. While Google provides the in_app_updates toolkit to handle updates seamlessly, iOS doesn’t offer a similar solution.

If you search online for ways to force an iOS application update, you’ll likely find methods that involve displaying a dialog box redirecting users to the App Store. While this approach can work, it’s not always effective. Once users leave the application, there’s a significant chance they won’t return to update and reopen the app.

ios_force_update

How to Check for Updates

To determine whether an update is available, there are a couple of options:

Option 1: Using the iTunes Lookup API

The iTunes Lookup API can be a useful tool for retrieving the latest version from the App Store. However, it comes with several limitations:

  1. Data Consistency: The information returned may not always be up-to-date, leading to discrepancies between the API and the App Store.

  2. Limited Metadata: The API provides only essential app details, lacking comprehensive information such as detailed changelogs or version history.

  3. Country-Specific Restrictions: Responses can vary by country, which may lead to inconsistencies in the app's availability or metadata.

  4. Empty Responses: For some app IDs, the API may return empty data arrays ([]), indicating that no information could be found, which can be frustrating for users trying to retrieve app details.

  5. Error Handling: The API can return ambiguous error messages, making it challenging to troubleshoot issues effectively.

Option 2: Best Solution

A more effective solution is to use server-side configuration, either via an API or remote configuration, to compare the app's local version with the latest version available. This approach provides greater control over the update process compared to relying on the iTunes API.

Other options, such as web scraping from the App Store URL, exist but are not efficient for this purpose.

meme2

Creating a Native App Updater for iOS

Using Platform Channels

For creating native app updates, Flutter uses platform channels. If you are not familiar with platform channels, think of them as a bridge between natively written code (in Swift, Java, Kotlin, or JavaScript) and the respective platforms (iOS, Android, Web, Windows).

For more information about platform channels.

StoreKit

To ensure a smooth in-app update experience for iOS, the StoreKit framework provided by Apple will be used. For a quick explanation, let's have a little chat with ChatGPT:

ChatGPT (Not Pro Version): Hello, I am ChatGPT. How can I help you?

Me: Explain StoreKit iOS.

ChatGPT (Not Pro Version): Giving your personal data to Sam Altman, thanks. Fetching...

ChatGPT (Not Pro Version): StoreKit is a framework provided by Apple that allows you to integrate in-app purchases (IAPs) and subscriptions into your iOS, macOS, watchOS, and tvOS applications. It provides the tools needed to manage products, handle transactions, and maintain user receipts.

Thinking this is enough to implement this, but if you want to explore more in detail, check out StoreKit.

Getting Started

  1. Create a Flutter Project

  2. Add the following dependencies for getting the app's local version. You can either add this to pubspec.yaml:

   dependencies:
     package_info_plus: <latestVersion>
Enter fullscreen mode Exit fullscreen mode

Or run the following command:

   flutter pub add package_info_plus
Enter fullscreen mode Exit fullscreen mode
  1. Now open your app in Xcode:
   cd ios && open Runner.xcodeproj
Enter fullscreen mode Exit fullscreen mode
  1. Open the AppDelegate.swift file and add the following content to create a platform channel for using StoreKit.
  1. In Flutter, check if an update is available:
  1. If an update is available, call the platform-specific method:
  1. That's it! Run your application.

ios-flutter-pod-meme

Demo

For demonstration purposes, I am using the Bitwarden app ID because Apple won’t allow me to publish my to-do app on the** App Store**.

Source code

Follow me:

Top comments (0)