Using App Clips with Mobile Foundation apps on iOS 14

In Apple’s WWDC 2020, Apple introduced a new feature called App Clips for iOS 14 which allows to access the app without actually installing the app on the device just like instant apps for Android.

iOS 14 App Clips
Picture Source: Apple.com

References

See here, for details on AppClips.

In this tutorial, we will use PincodeSwift iOS Application to create an App Clip. We will be adding a simple button that will fetch the account balance using a resource adapter.

Create an App Clip Target

Open PincodeSwift in Xcode, Go to File > New > Target and Select App Clip and fill the product name as PincodeSwiftAppClip, click Finish.

AppClip Target

This will add a new App Clip target to the existing iOS Application.

NOTE: CocoaPods does not officaly have support for App Clips integration. So in-order to use MobileFoundation SDK with AppClips, the framework should be attached manually to the AppClip target

AppClip Target

Adding Logic for fetching the balance from the Resource Adapter

  • In the ContentView.swift file import the IBMMobileFirstPlatformFoundation

       import IBMMobileFirstPlatformFoundation
    
  • Then add a button for fetching the balance from the Resource Adapter

      Button("Get Balance", action: {
        let request = WLResourceRequest(url: URL(string: "/adapters/ResourceAdapter/balance"), method: WLHttpMethodGet)
        request?.send { (response, error) -> Void in
            if(error == nil){
                print((response?.responseText)!)
                let alert = UIAlertController(title: "Balance",
                    message: (response?.responseText)!,
                    preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action) -> Void in
                }))
                DispatchQueue.main.async {
                    let topController = UIApplication.shared.keyWindow!.rootViewController! as UIViewController
                    topController.present(alert,
                        animated: true,
                        completion: nil)
                }
            }
            else{
                print(error.debugDescription)
            }
        }
      })
    

    Here we are making a WLResourceRequest adapter call to the Mobile Foundation server to retreive balance and shows an alert once the balance amount.

  • Register the seperate iOS application in Mobile Foundation Operations console for App Clip target with bundle ID as com.sample.PinCodeSwift.Clip and update Mobile Foundation server info in the MFP Configuration file of PinCodeSwiftAppClip Target.

  • Map the accessRestricted with empty value in Mobile Foundation Operations console for App Clip target. Scope Mapping

That’s all, You are now done with adding App Clip to the PincodeSwift application.

AppClip Balance

Source Code

The source code of the application is uploaded in GitHub repository.

Conclusion

App Clips are a great way for users to quickly access and experience what your app has to offer. An App Clip is a small part of your app that is discoverable at the moment it is needed. App Clips are fast and lightweight so a user can open them quickly. For Example, when users are ordering take-out from a restaurant, renting a scooter, or setting up a new connected appliance for the first time, users will be able to start and finish an experience from your app in seconds. And when they are done, you can offer the opportunity to download your full app from the App Store

Last modified on September 23, 2020