App Clips on iOS 14: How To Develop

sunny
5 min readJul 5, 2020

What is App Clip

An app clip is a lightweight version of your app that offers some of its functionality where and when users need it.

With Xcode, you can add an app clip target to your app’s Xcode project and share code and assets between the app clip and app.

What are the Benefits of the App clips

Create an app clip that launches instantly and offers some of its associated app’s functionality to users who don’t have the full app installed.

App Clips offer is how they address concerns over data privacy. Because App Clips are essentially a way to run app code on-demand, they’re restricted from tapping into iPhone’s more sensitive data — like health and fitness information. Plus, the App Clip and all its data will automatically disappear if it’s not used again within some period of time.

Users Can Launch App Clips Following invocations

1. Scanning an NFC tag or visual code at a physical location

2. Tapping a location-based suggestion from Siri Suggestions

3. Tapping a link in the Maps app

4. Tapping a Smart App Banner on a website

5. Tapping a link that someone has shared in the Messages app

Ways to launch App Clips

Publish Your App Clip

App clips require a corresponding app. When you’re ready to publish your app clip, submit it as part of your app’s archive. Note that your app clip must pass the App Store review process after you submit it for review.

Limitation of App Clips

App clips must be small — no more than 10 MB — to provide an instantaneous launch. If possible, keep your app clip well below this limit.

So this means what evermore that 10 MB size of the app we can’t create App clips, no it’s saying about app clip size, not for the full app. So if your app has 100 MB or more, still we can create App Clip for that app. App clip is a kind of extension or a lightweight version of your full App.

Require to develop App Clips

• iOS SDK version — 14.0

• Xcode version — 12

• App has a universal link setup we can leverage for APP clips. (apple-app-site-association)

• Appstore account.

So let's start developing App Clips

Add an App Clip Target

App clips require a corresponding app that offers at least the same functionality as the app clip, and you typically use the same Xcode project for both your full app and your app clip. If you’re starting a new app project, first create a new iOS project with Xcode. If you want to add an app clip to your existing app, open its Xcode project. Then, add an app clip target to the Xcode project:

  1. Add a new target using the App Clip template.
  2. Choose a product name, select applicable options for your app clip, and click Finish.

Xcode creates all required files for the options you choose, and adds a target for your app clip with:

  • A scheme to build and run your app clip and its tests. To build and run your full app, continue using your existing schemes.
  • A new capability named On-Demand Install Capable.
  • The Parent Application Identifiers Entitlement.
  • An app identifier for the app clip, using the full app’s app identifier as its prefix, followed by a string. For example, if your full app’s app identifier is $(AppIdentifierPrefix)com.example.MyApp, the app clip’s app identifier would be $(AppIdentifierPrefix)com.example.MyApp.Clip.
  • The _XCAppClipURL environment variable as part of the app clip’s scheme that allows you to test invocations.
  • Support for the same devices as the full app, not including macOS.

In addition, Xcode creates a new build phase for the app target that embeds the app clip in the app.

Before you add your own code to the app clip target, run the app clip in the simulator or on a device. At this point, the app clip shows an empty white screen because you haven’t added any code and assets yet.

Add the Associated Domains Entitlement

Users launch app clips from invocations that pass an invocation URL to the app clip or, if the user installs the app to replace the app clip, to the full app. No matter which invocations you choose to support, you must add the Associated Domains Entitlement to the app and the app clip targets:

1. Open your project in Xcode; then, in your project settings, enable the Associated Domains capability to add the Associated Domains Entitlement.

2. For each URL that launches your app clip or full app, add its domain to the Associated Domains capability using this pattern: appclips:<fully qualified domain>. For example, add appclips:example.com.

In addition to adding the Associated Domains Entitlement, you must make changes to your server to allow the system to validate your app clip before launch. For more information, see Configuring Your App Clip’s Launch Experience.

Make Changes to Your Server and Your Xcode Project

And if your app does not have Apple App Site Association file to your server then follow below link

https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app

Update the apple-app-site-association file, suppose if your App all ready have universal link set up or Apple App Site Association file, add app clips entry to that.

Add code handle NSUserActivity

Use Active Compilation Conditions

When you share code between the app clip and the full app, you may encounter cases where you can’t use some of your app’s code in the app clip. In these cases, take advantage of the Active Compilation Conditions build setting, where you can declare a condition to exclude code.

Start by navigating to your app clip target’s build settings and creating new value for the Active Compilation Condition build setting; for example, APPCLIP. Then add a check in your shared code, where needed, to exclude code you don’t want to use in your app clip.

The following code checks for the APPCLIP the value you added to the Active Compilation Conditions build setting.

Now build, run, and debug your app clip in the simulator or on a device.

The above information is collected from the following links. Please go through the following links if you need more info.

https://developer.apple.com/videos/play/wwdc2020/10146/

Download Apple sample code https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui

--

--