MacKuba

Kuba Suder's blog on Mac & iOS development

App Clips

App ClipsAppKitExtensionsFoundationLocationMacMapsPhotosPrivacySafariSwiftSwiftUIUIKitWatchKitWWDC 19WWDC 20

View as index

Streamline your app clip

Categories: App Clips, UIKit, WWDC 20 0 comments Watch the video

(Watch the “Explore app clips” and “Configure and link your app clips” videos before.)

App clips are designed for speed of interaction – interaction needs to be focused on a specific goal and essential tasks

Leave any advanced or complex features for the main app

App clip should be usable immediately when launched

  • include any assets that will be needed immediately in the bundle
  • don’t add a splash screen
  • don’t ask people to log in or sign up before they can perform the task they want
  • ask for permission to access data only if it’s required and only at the moment when you need it

The main app should present the same experience in the same way

The app clip should have the same name and icon as the app

Organizing the project:

Keep in mind that the smaller the app clip bundle is, the faster your users can launch it, so only include what you really need in the bundle

Put shared assets in a separate shared asset catalog

Use Sign in with Apple, ASWebAuthenticationSession or password autofill for logging in

Consider giving an option to upgrade the account to Sign in with Apple if the user logs in using a password

App clips are ephemeral – users should be able to try them out easily while trusting that their privacy is being protected

Some user data is not accessible

You can ask for permission to camera, microphone and Bluetooth

Location access

Don’t ask for location access to determine which physical store the user is in – encode the store ID in the URL

To make sure they’re in the right store, you can use a new API to confirm the location that you already assume you know:

  • add NSAppClipRequestLocationConfirmation to NSAppClip dictionary in the Info.plist
  • get a payload object from userActivity.appClipActivationPayload
  • run payload.confirmAcquired(in: region) { … } (you can set a radius of up to 500m)

Notifications

Ephemeral notifications: you can ask for permission to send the user notifications up to 8 hours after the app clip is accessed

This does not show a regular popup asking for permission (user can refuse access in the initial app clip sheet)

Add NSAppClipRequestEphemeralUserNotification to the dictionary

When ephemeral access is granted, authorizationStatus in UNUserNotificationCenter will be set to .ephemeral

Migrating to the app

After the app clip is activated, a banner is shown at the top of the screen for a moment that leads you to the app’s page in the App Store

You can also use a new SKOverlay from StoreKit to show a popup recommending the app to the user

.appStoreOverlay() in SwiftUI

Do this after they finish the task

Passing data from the app clip to the app: use an app group container

You can also pass Sign in with Apple authorization:

  • get the user ID authorization.credential.user from the Sign in with Apple authorization success handler
  • save it as a file inside the group container (containerURL(forSecurityApplicationGroupIdentifier: “…”))
  • on the app side, read the file and pass it to ASAuthorizationAppleIDProvider: getCredentialState(forUserId: user)

Configure and link your app clips

Categories: App Clips, UIKit, WWDC 20 0 comments Watch the video

(Watch the “Explore app clips” video before.)

App Clips provide an entry point for your users with minimal friction

Touching a physical NFC tag  ⭢  NFC tag encodes a URL  ⭢  your app’s clip configured for that URL shows up as a popup  ⭢  when user presses Open, it’s open in full screen

App clips can also be accessed from: QR codes, Maps, Safari (Smart App Banners), Messages, Siri suggestions

Tools will be available later this year that can create special circular app clip QR codes

Steps to configure:

Configure your web server

Set up the apple-app-site-association file (in .well-known folder)

Add an appclips key:

“appclips”: {
    “apps”: [“ABDE12345.com.example.app”]
}

Configure the app clip for handling links

  • add an associated domains entitlement to the app clip target
  • add a domain prefixed with appclips:, e.g. appclips:example.com
  • handle opening the app with NSUserActivity containing a given URL
  • in SwiftUI: .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { … }
  • in UIKit: scene(_: continue userActivity:)

Once the user has the full app installed, opening the same URL opens the full app instead of the clip – so the app needs to be able to handle the same URLs and show the same content

When testing in Xcode, you can set up a scheme that sets the environment variable _XCAppClipURL to the given URL

Configure app clip experiences on App Store Connect

Prepare metadata for the app clip:

  • Title up to 18 chars
  • Subtitle up to 43 chars
  • Header image: 3000×2000, aspect ratio 3:2, jpeg or png with no transparency

Set up on App Store Connect in a new section that appears once you upload a build with an app clip

If you want the clip to be accessible from more than Safari or Messages (e.g. QR codes), you need to set up “Advanced App Clip Experiences”

One app can set up multiple advanced app clip experiences matching different URLs

URL is matched based on the most specific prefix, so you can have one general catch-all URL and other more specific ones

App Clips can also be accessed by TestFlight testers – configure in “App Clip Invocations” sections in TestFlight on App Store Connect

Configure the Smart App Banner

Standard app banner:

<meta name='apple-itunes-app' content='app-id=12345678'>

For an app clip, add app-clip-bundle-id inside:

<meta name='apple-itunes-app' content='app-clip-bundle-id=com.example.fruta.clip, app-id=12345678'>

Explore app clips

Categories: App Clips, UIKit, WWDC 20 0 comments Watch the video

App clip is a part of an app – you need to have an app to add an app clip

App Clip Experience – a specific URL configured to display an app clip popup sheet on iOS 14 when opened in some app

App clip itself  ⭢  an on-demand binary

App clip experience is a new entry point to your app

Configured in a similar way as Universal Links, + additional setup in App Store Connect

App clip appears whenever a user accesses that URL: through a QR code or NFC tag, links in Safari and Messages, places in Maps

Also through Siri suggestions

Coming later this year: special Apple-designed circular QR codes for app clips

App clip

Created as another target in your app project in Xcode

Uploaded to App Store Connect together with the whole app

Once the app containing an app clip is released, the app clip will be downloaded separately when its URL is opened by the user

→ if the full app is already installed, it will be launched instead, so it must be able to do everything that the clip does

App clips are designed to be downloaded quickly in the background, so they should be as small as possible

App clip bundle must be less than 10 MB after thinning

Include only what is needed immediately, and download other assets and data from the internet when needed

Include only a minimal part of the app UI in the app clip, only what will be required in this specific context where the app clip will be used

App clips should generally not include top level parts of your navigation flow, like tab bars; also things like profile screens

They should deep-link to the specific screen in the app that they are concerned with

Use separate URLs for any distinct experiences, each app clip experience should focus on one thing

E.g. if you have multiple physical stores, have separate URLs for each store so that you can skip a “Choose store” screen

An app clip receives an NSUserActivity with the given URL when launched

App clips can use any frameworks from the iOS SDK (including Apple Pay and notifications), and use UIKit or SwiftUI app lifecycle

Access to some sensitive user data is limited (e.g. no access to HealthKit)

New location confirmation API – lets you confirm if the user really is where you think they are

You can migrate data from the app clip to the full app using a group container

→ group container is deleted when the data is migrated

Autorizations for camera, microphone and Bluetooth access are automatically migrated to the app when installed

App clip and its storage are deleted from user’s device after a period of inactivity (~ several days)

App clips also aren’t included in backups

Any app clip data should be treated more like a cache

If a specific app clip is used frequently, iOS will keep it on device for a longer period after last use

App clip can’t register as document or URL scheme opener, it can only be opened using the URL configured in the app clip experience

They also can’t include their own extensions, like content blockers

SKOverlay or .appStoreOverlay in SwiftUI – a standard UI for inviting your users to the full app

Use ASAutthorizationController if you need a way to log the user in to an account