Swift

Project permissions

As you'll be using the microphone when making a call, you need to request the permission to use it.

Info.plist

Every Xcode project contains an Info.plist file containing all the metadata required in each app or bundle - you will find the file inside the PhoneToApp group.

A new entry in the Info.plist file is required:

  1. Hover your mouse over the last entry in the list and click the little + button that appears.

  2. From the dropdown list, pick Privacy - Microphone Usage Description and add Microphone access required in order to make and receive audio calls. for its value.

Your Info.plist should look like this:

Info.plist
Info.plist

Request permission on application start

Open AppDelegate.swift and import the AVFoundation library right after where UIKit is included.

import UIKit
import AVFoundation

Next, call requestRecordPermission: inside application:didFinishLaunchingWithOptions::

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    AVAudioSession.sharedInstance().requestRecordPermission { (granted:Bool) in
        NSLog("Allow microphone use. Response: %d", granted)
    }
    return true
}

Build and Run

You can now build and run the project, by either selecting Product > Run from the top menu, or pressing Cmd + R, and launch it in the simulator.

Notice the prompt asking for permission to use the microphone:

Simulator microphone permission ask
Simulator microphone permission ask