Recording from the microphone is a tricky task – with a fair bit of setup. However it’s all laid out here in plain language 🙂

1. The very first step is to request permission to use the microphone:

In your Info.plist set the following property:

Privacy – Microphone Usage Description, Set the string to whatever you want to say to your user. Here’s a screenshot:
Screen Shot 2016-08-06 at 19.38.38

2. Request permission, this should be fired from within the current View Controller:

If the above doesn’t show anything MAKE SURE you’ve done step 1. No description in the Info.plist means it won’t ask for permission!

Note that if the user denies access then you cannot fire off another permission request. The USER has to go into settings and manually change permission (you should perhaps tell them this).

3. Now it’s time to setup recording. I’m doing this from within a View Controller (most common case) but you can adapt instructions according to your needs.

Inherit from AVAudioRecorderDelegate

Create a class level variable to hold the recorder. Be careful not to create this inside a function as you may encounter scope problems)

4. Create a URL path where you’ll store the recording. This is usually the documents folder of your app.

5. And now for the recording!

6. Optional but do it if you’re a good programmer. Set up the delegate function that fires when recording ends:

I use the above step to update my UI and tell the user if anything is messed up!

That’s all folks!

How to Record Sound with Swift 4 and iOS 12
Tagged on:                 

One thought on “How to Record Sound with Swift 4 and iOS 12

  • January 15, 2018 at 7:56 pm
    Permalink

    Could you upload a project file?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This

Exhausted by your 9 - 5?

Would you prefer to work for half the time and earn double? The first step to your freedom is understanding how apps make money. Simply enter your email below and I will send you a free PDF describing the process.

If you're serious about improving your life then do not miss this opportunity.


You have subscribed! Please check your email to confirm this subscription and to receive your item!