Shake It, Baby!
To make apps appeal to our audience we add different animations or sounds, creating a connection between user and app. For this blog, I followed a tutorial which showed me how to add small app snippets of sound that play when you shake the phone. I used AVFoundation framework to add sound to the app.
So, let’s make this app.
Create a new project. To add sound to your app, you must import the AVFoundation Framework. Click on your project name, on the top left corner. Then choose Target -> Build Phases -> Link Binary With Libraries.

Press “+” sign.
In the search bar find the framework you need and add it. AVFoundation framework is amazing! Go and find more about it here.
Now let’s code a little bit.

- Importing framework to your file. Now we have access to all AVFoundation methods.
- Creating a variable of type AVAudioPlayer.
- Writing a function which takes two parameters.
Creating a variable of type Array where we are storing the names of our sounds as Strings. There is a great website where you can find a bunch of sounds for free. Just download the sounds you want and then drag and drop them to your project. Name them properly and short for convenience. We are going to use the names in our Array.
5. Detecting a shake motion.
6. Creating a random number to use as an index number for plucking out a random sound name from our Array.
7. Getting the file location for our sound.
8. Try to find the sound using the fileLocation and play it if found.
Done. Super easy! Shake It Baby!

References:
Looking to take your app developing to the next level? Or maybe you're just starting out and want an income boost as a…www.udemy.com