0
0
iOS Swiftmobile~10 mins

App Clips overview in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an App Clip target in Swift.

iOS Swift
import SwiftUI

@main
struct MyAppClip: [1] {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}
Drag options to blanks, or click blank then click option'
AApp
BAppClipApplication
CAppClip
DAppClipMain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'App' instead of 'AppClip' causes the app to be a full app, not an App Clip.
2fill in blank
medium

Complete the code to present the App Clip experience when a user scans a QR code.

iOS Swift
func handleQRCode() {
  let url = URL(string: "https://example.com/appclip")!
  UIApplication.shared.[1](url, options: [:], completionHandler: nil)
}
Drag options to blanks, or click blank then click option'
AstartAppClip
BlaunchAppClip
CopenAppClip
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'openAppClip' causes compile errors.
3fill in blank
hard

Fix the error in the code that configures the App Clip's invocation URL in the Info.plist.

iOS Swift
"NSUserActivityTypes" = ["[1]"]
Drag options to blanks, or click blank then click option'
Acom.example.appclip
Bcom.example.appclip.invocation
Ccom.apple.corespotlightitem
Dcom.apple.appclip
Attempts:
3 left
💡 Hint
Common Mistakes
Using system identifiers like 'com.apple.appclip' will not work for your App Clip.
4fill in blank
hard

Fill both blanks to create an App Clip experience that uses a specific invocation URL and a fallback URL.

iOS Swift
let invocationURL = URL(string: "https://example.com/[1]")!
let fallbackURL = URL(string: "https://example.com/[2]")!
Drag options to blanks, or click blank then click option'
Alaunch
Bstart
Chome
Dfallback
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same path for both URLs causes confusion in the app launch process.
5fill in blank
hard

Fill all three blanks to define an App Clip invocation using NSUserActivity with a URL and a title.

iOS Swift
let activity = NSUserActivity(activityType: "com.example.appclip.invocation")
activity.webpageURL = URL(string: "https://example.com/[1]")
activity.title = "[2]"
activity.isEligibleForPrediction = [3]
Drag options to blanks, or click blank then click option'
Alaunch
BApp Clip Launch
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting isEligibleForPrediction to false disables helpful system features.