Using Haptics in your App
Haptics can be very useful to provide feedback to the user, for example after the user has performed an action. SwiftyLaunch makes it trivial to add Haptic feedback to your app.
To access Haptics, use static functions the Haptics
class from SharedKit:
Interactive Haptics ("Notification Feedback")
These types used after a user has performed an action. We use this types of haptics when we show an in-app notification.
import SharedKit
func performUserAction() {
// ...
if (success) {
Haptics.notification(type: .success)
} else {
Haptics.notification(type: .error)
}
}
Function definition:
Haptics.swift
public class Haptics {
static public func notification(type: UINotificationFeedbackGenerator.FeedbackType) {}
}
type
: The type of haptic feedback to generate. Three types are available:.success
,.warning
, and.error
.
Impact Haptics ("Physical Feedback")
This type of haptic feedback is best used when the user directly interacts with the app, like after tapping a button to simulate a physical impact.
import SharedKit
func buttonTapped() {
Haptics.impact(style: .soft)
}
Function definition:
Haptics.swift
public class Haptics {
static public func impact(style: UIImpactFeedbackGenerator.FeedbackStyle) { }
}
style
: The style of haptic feedback to generate. Available styles:.light
,.medium
,.heavy
,.soft
, and.rigid
.
⚠️
Don't overuse haptics, as it can be annoying to the user.