Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

mergesort/FeedbackEffect

Repository files navigation

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

BuddyBuildPod VersionSwift VersionLicense MITPlaform

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 effectsand 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.

letselectionFeedback=HapticFeedback.notification(.success)letsoundUrl=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 ofSoundEmitting. 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 toSoundEmitting 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. BothHapticFeedback andVibrationFeedback conform toHapticEmitting.

  • HapticFeedback: Uses iOS's built inUIFeedbackGenerator to generate feedback effects. You can use this just how you would normally useUIImpactGenerator,UISelectionGenerator, andUINotificationFeedbackGenerator.

  • VibrationFeedback: For older devices which do not have a taptic engine. It will generate similar vibration patterns to theUIFeedbackGenerator, which unfortunately do not matchUIFeedbackGenerator 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.

letnotificationFeedback=HapticFeedback.selectionlettapSound=SoundEffect.tapFeedbackEffect.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.

letselectionFeedback=HapticFeedback.notification(.success)letsoundUrl=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.

letvibration=VibrationFeedback.notificationletsound=MessageTone.tweetFeedbackEffect.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.

letvibration=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 usingCocoaPods for version 1.5.0 or below you can installFeedbackEffect by adding it to yourPodfile:

platform:ios,'10.0'use_frameworks!pod'FeedbackEffect'

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

About me

Hi, I'mJoe everywhere on the web, but especially onTwitter.

License

See thelicense for more information about how you can use TypedNotifications.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp