App Clip Trilogy
- Learn how to create a good App Clip in iOS14
- Create a little Apple App, App Clip, what you should know
- How to make your App Clip have a good user experience
preface
Create a little Apple App, App Clip, which things you should know
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
- Create an iOS project using Xcode
- Create a new Target for the iOS project using the App Clip Template
- 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:
- Enable the project Settings and add the Associated Domains Entitlement to the Associated Domains Capability
- 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. #endifCopy 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
- Open Xcode for Associated in app and app Clip
Domains Entitlement Configures the server domain name
Register App Clip with 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.
As an ios developer, when I encounter problems, it is particularly important to have a learning atmosphere and a communication circle, which is of great help to myself. This is my ios communication group: 711315161, sharing BAT, Ali interview questions, interview experience, discussing technology, and learning and growth together! Hope to help developers avoid detours.