Using App Clips with Mobile Foundation apps on iOS 14
Raja Rahul October 22, 2020
Mobile_Foundation iOS App ClipsIn 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.

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.

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

Adding Logic for fetching the balance from the Resource Adapter
-
In the
ContentView.swift
file import theIBMMobileFirstPlatformFoundation
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 ofPinCodeSwiftAppClip
Target. -
Map the
accessRestricted
with empty value in Mobile Foundation Operations console for App Clip target.
That’s all, You are now done with adding App Clip to the PincodeSwift application.

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
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.