App Clips for iOS: Getting Started
In this tutorial, you’ll learn how to design and implement App Clips. By Graham Connolly.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
App Clips for iOS: Getting Started
25 mins
- Getting Started
- What Exactly Is an App Clip?
- Adding an App Clip Target
- Sharing Assets and Code Between Targets
- Sharing Code and Assets
- Designing the App Clip Experience
- Getting App Clip Experience Data
- Simulating a Clip Launch
- What Lemonade Stand Is This?!
- Ordering Some Lemonade
- Can’t Find a Lemonade Stand?
- Setting up Location Confirmation
- Using Custom Flags
- Disabling Ordering
- Showing an Alert
- Simulating Location
- Putting it all Together
- Using Ephemeral Notifications
- Where to Go From Here?
Using Ephemeral Notifications
Like a main app, App Clips can receive notifications. These can add great value to App Clips by notifying you when your order is ready. App Clips can receive notifications only for a short time after getting launched — up to eight hours.
Open the Info.plist of your App Clip and enable ephemeral notifications — it’s in the same place as the location confirmation permission:
This enables notifications for the App Clip, but the user can opt in on the App Clip Card. As a result, in SwiftyLemonadeClipApp.swift, add the following code below handleUserActivity(_:)
:
func requestNotificationAuthorization() {
//1
let notifCenter = UNUserNotificationCenter.current()
notifCenter.getNotificationSettings { setting in
//2
if setting.authorizationStatus == .ephemeral {
return
}
//3
notifCenter.requestAuthorization(options: .alert) { result, error in
print("""
Authorization Request result: \(result) \
- \(String(describing: error))
""")
}
}
}
This code:
- Retrieves the notification settings for the app
- Checks to see the if app is authorized to receive ephemeral notifications. If access is already granted, then there is no need to continue. But if access is not granted, then request it again.
Finally, while still in SwiftyLemonadeClipApp.swift, add the following code to the end of body
. Be sure it appears inside the closing brace for WindowGroup
:
//1
.onAppear {
requestNotificationAuthorization()
}
This code calls requestNotificationAuthorization()
when this view appears.
There you go! You don’t need to miss all the soccer action now, with notifications enabled.
Where to Go From Here?
You can download the completed project files by clicking the Download Materials button at the top or bottom of the tutorial.
In this tutorial, you learned how to:
- Add an App Clip target
- Share assets and code
- Use the Location Confirmation API to verify you are at the correct location
- Set up App Clip notifications
If you enjoyed this tutorial, check out SwiftUI by Tutorials. You’ll take a deep dive into how to define what your app’s UI should do with concise, declarative language, and say goodbye to tons of confusing UIKit code.
If you are interested in learning more about App Clips, check out Apple’s Documentation.
If you have any questions or comments, join the forum discussion below.