preface

In the Xcode project, you can add an App Clip target to your App. With Xcode, the App Clip can share code and resources with your App, and can be compiled, debugged, and run in real machine or emulator environment. However, in practice, developers must verify the effectiveness of app Clip on their own servers.

Add an App Clip Target

  1. Create an iOS project using Xcode
  2. Create a new Target for the iOS project using the App Clip Template
  3. Enter the name of the App clip and select the appropriate option for the App Clip and click Finish

With the above steps, Xcode will automatically create the required file for you and generate the following content for the Target of your app Clip:

  • A scheme for compiling, running, and testing your app clip
  • The new capability
  • Parent Application Identifiers Entitlement.
  • App bundleID clip
  • Test the AppClip environment variable _XCAppClipURL
  • Support device debugging

When the creation is complete, run the App Clip on the simulator or real machine to see if any error is reported.

Add the Associated Domains Entitlement

  • The App clip can be invoked by a URL passed in by the user (e.g., scan code)
  • Users can install a complete app by passing a URL to the main app using app Clip

To support the above two invocation methods, the Associated Domains Entitlement must be added to app and app clip:

  1. Enable the project Settings and add the Associated Domains Entitlement to the Associated Domains Capability
  2. Add its domain to the Associated Domains Capability feature using the following style: AppClips :.

Add code and resources

Writing code logic for App Clip and adding asset resources is no different from normal iOS App development, but for project maintainability, App Clip should share as much code with the full application as possible:

  • If you create a new app with App Clip, follow best practices based on code modularity, for example, creating reusable components.
  • If an app Clip is added to an existing app, it is recommended that you spend some time reconstructing the code to be modular and share it with the App Clip to avoid code duplication
  • Assets are shared between the complete application and app Clip

Use Active Compilation Conditions

When sharing code between the App Clip and the full application, you may encounter situations where you cannot use some code in the App Clip. In these cases, set up Active Compilation Conditions in which you can declare Conditions that exclude code.

Locate the Active Compilation Conditions in the app Clip project Settings and add a value to them, such as APPCLIP, then add interpretation to the shared code as shown in the following example:

#if ! APPCLIP
// Code you don't want to use in your app clip.
#else
// Code your app clip may access.
#endif
Copy the code

Server Configuration

Before the app Clip is displayed or invoked, the system verifies the configuration of the APP Clip and the INVOKED URL. If validation cannot be performed, the App Clip will not be displayed and will not start. To enable the system to authenticate your app Clip, you need to configure your Web server and Xcode project:

  • Add an Apple App Site Association file to your server
  • Add a key-value pair to the Apple App Site Association file with the key as AppClips, for example:
{
    "appclips": {
        "apps": ["ABCED12345.com.example.MyApp.Clip"]}... }Copy the code
  • Run Xcode to configure the server domain name for app and the Associated Domains Entitlement in app Clip

Register the App Clip in App Store Connect

The system launches your App clip using the URL you configured in App Store Connect. Therefore, identifying the urls that launch app Clips, responding to them at startup, and registering them in App Store Connect are critical to creating app Clips.

Release the App Clip

When you are ready to publish app Clip, submit it as part of the App Archive. Please note that you must be approved by the App Store before publishing.

At the end

Ok, that’s all for today’s explanation. Interested friends can pay attention to my technical public account. There are high-quality technical articles pushed every week.