• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library for playing sounds and providing haptic feedback with ease.

FeedbackEffect

A μ library for playing sound effects and providing haptic feedback… with ease.

BuddyBuild Pod Version Swift Version License MIT Plaform

Your app should be special. Other people's apps suck. How do we make your app extra awesome? Feedback and sound effects my friend.

Until now there has not been a unified API to allow you to integrate sound effects and haptic feedback with ease. If you're guessing that now there is, then you're right… now there is.


The API couldn't be simpler.

let selectionFeedback = HapticFeedback.notification(.success)
let soundUrl = Bundle.main.url(forResource: "Success", withExtension: "m4a")
FeedbackEffect.play(sound: soundUrl, feedback: selectionFeedback)

Q&A time

Q: Is that all?

A: Yep.

Q: Really?

A: Fine, let's go into more detail.


SoundEmitting

There are two kinds of SoundEmitting. You can provide a URL to any resource that iOS can play (such as an m4a), or use some common sounds from iOS pre-configured.

Three types conform to SoundEmitting out of the box:

  • URL
  • MessageTone
  • SoundEffect

If you'd like to add some more, all you have to do is conform to the protocol. If you find some more that are built into iOS, feel free to file a PR and it'll gladly be accepted.


HapticEmitting

There are two ways to provide a user with haptic feedback. Both HapticFeedback and VibrationFeedback conform to HapticEmitting.

  • HapticFeedback: Uses iOS's built in UIFeedbackGenerator to generate feedback effects. You can use this just how you would normally use UIImpactGenerator, UISelectionGenerator, and UINotificationFeedbackGenerator.

  • VibrationFeedback: For older devices which do not have a taptic engine. It will generate similar vibration patterns to the UIFeedbackGenerator, which unfortunately do not match UIFeedbackGenerator exactly one for one but are rather close.


Q&A part II

Q: Is that it?

A: Yep. You're on your own from here padawan. Let's leave you with a few more examples to make you feel safe though.


Examples

Uses the haptic feedback built into iOS along with the tap sound to make a user feel like they're really tapping a button.

let notificationFeedback = HapticFeedback.selection
let tapSound = SoundEffect.tap
FeedbackEffect.play(sound: tapSound, feedback: notificationFeedback)

Uses the haptic feedback built into iOS along with an success sound to make a user feel they've completed a unit of work successfully.

let selectionFeedback = HapticFeedback.notification(.success)
let soundUrl = Bundle.main.url(forResource: "Success", withExtension: "m4a")
FeedbackEffect.play(sound: soundUrl, feedback: selectionFeedback)

Uses the vibration feedback fallback (for users without 3D Touch devices) built into iOS along with a pre-configured sound effect.

let vibration = VibrationFeedback.notification
let sound = MessageTone.tweet
FeedbackEffect.play(sound: sound, feedback: vibration)

You can use just one at a time too if you wish. Just provide haptics and leave the sound parameter nil. You can also do the opposite and provide a sound with no haptics.

let vibration = HapticFeedback.notification(.error)
FeedbackEffect.play(sound: nil, feedback: vibration)

Requirements

  • iOS 10.0+
  • Xcode 8.0+

Installation

SPM will be the default supported installation method from version 1.5.0 and higher, so please integrate by using SPM.

If you're still using CocoaPods for version 1.5.0 or below you can install FeedbackEffect by adding it to your Podfile:

platform :ios, '10.0'
use_frameworks!

pod 'FeedbackEffect'

Or install it manually by downloading FeedbackEffect.swift and dropping it in your project.

About me

Hi, I'm Joe everywhere on the web, but especially on Twitter.

License

See the license for more information about how you can use TypedNotifications.

More Repositories

1

Boutique

✨ A magical persistence library (and so much more) for state-driven iOS and Mac apps ✨
Swift
774
star
2

TableFlip

A simpler way to do cool UITableView animations! (╯°□°)╯︵ ┻━┻
Swift
552
star
3

Public-Extension

🔧 A weekly log of handy Swift extensions
Swift
298
star
4

Bodega

A simple store for all your basic needs, and a foundational data layer primitive for iOS and Mac apps. 🐱
Swift
252
star
5

Slope

A simpler way to implement gradients on iOS.
Swift
238
star
6

GenericCells

Creating generic UITableViewCells and UICollectionViewCells instead of subclasses.
Swift
82
star
7

Anchorman

An autolayout library for the damn fine citizens of San Diego.
Swift
79
star
8

TypedNotifications

A mechanism for sending typed notifications with payloads across your iOS app.
Swift
76
star
9

MVCS

Swift
51
star
10

UILabel-ContentSize

Get the content size of a UILabel with text, because I always forget how to and want to have it in one god damn place.
Objective-C
44
star
11

CrossPromoter

A control which allows you to display an app to cross promote within your own app.
Objective-C
36
star
12

Communicado

A simpler way to share on iOS.
Swift
26
star
13

Shortcat

Navigate UITableViews using a keyboard with cat-like agility 🐱
Swift
12
star
14

Modem

A routing, serialization, and deep link handling framework all wrapped up in one
Swift
9
star
15

slack-themes

Slack Themes I've made and use
8
star
16

UIView-BezierCurve

Round individual corners of a UIView
Objective-C
7
star
17

UIViewController-StoreKit

A category on UIViewController allowing you to pull up an iTunes item with just one method
Objective-C
7
star
18

UIViewController-Sharing

A category on UIViewController for adding sharing options
Objective-C
6
star
19

UIControl-Notifications

Make your UIControls respond to notifications and blocks instead of the old fashioned target+selector approach
Objective-C
5
star
20

Launchpad

A better way to handle SwiftUI app launch
Swift
5
star
21

QuickNote

A scratch pad notification center widget for jailbroken iOS 5/6
Objective-C
4
star
22

iMessageFormatter

An Applescript to autoformat sentences with a capital letter and period at the end
AppleScript
4
star
23

UIDevice-Hardware

Category on UIDevice for accessing hardware information
Ruby
3
star
24

RequestBuilder

A library to help you build network requests atop URLSession
Swift
3
star
25

bot-of-conduct

JavaScript
3
star
26

JFTextFieldTableCell

A UITableViewCell subclass which supports inline editing, block handlers, and other niceties.
Objective-C
3
star
27

Podcatcher

A library for interacting with iOS Podcast apps
Objective-C
2
star
28

is-ci-busted

Is Ci Busted? Who even knows.
JavaScript
2
star
29

NSObject-Builder

Use the builder pattern with a category on NSObject
Ruby
2
star
30

QuickTweet

Add a quick way to send tweets from iOS's Notification Center.
2
star
31

UIImage-Transforms

Transforms on UIImage
Objective-C
2
star
32

JFFileManager

Class methods which make dealing with files on iOS easier.
Objective-C
2
star
33

NSString-Validation

A category on NSString for checking validity and transforming strings
Objective-C
2
star
34

SML

Random code I've done in SML for class
Standard ML
1
star
35

dropcaster-feed-seeder

Ruby
1
star
36

Google-Trends-Scraper

Get the list of google trends for every day from a certain point in time.
PHP
1
star
37

liftoff

Templates and Configuration for Liftoff
Swift
1
star
38

Project-Euler

My Objective-C implementation of the Project Euler solutions.
Objective-C
1
star
39

iosfolks.com

1
star
40

WebViewController

A simple web view controller, because everyone has their own version, but this one is simple with minimal chrome, and supports sharing out the box.
Objective-C
1
star
41

Response

An interface for creating a JSON response simply from a string
Go
1
star
42

NSDictionary-Networking

A category on NSDictionary for adding functionality when you're interacting with networking
Objective-C
1
star
43

Rerelease

A What's New screen, and more
Swift
1
star