AVAudioSession Swift

前端 未结 3 969
野趣味
野趣味 2020-12-19 02:27

I am trying to write a swift iOS app that will record the users voice. I have wrote the following code in swift however it fails to request mic permissions from the user. It

3条回答
  •  眼角桃花
    2020-12-19 02:56

    For Swift 3:

    let session = AVAudioSession.sharedInstance()
        if (session.responds(to: #selector(AVAudioSession.requestRecordPermission(_:)))) {
            AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
                if granted {
                    Linphone.manager.callUser(username: username)
    
                    print("granted")
    
                    do {
                        try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
                        try session.setActive(true)
                    }
                    catch {
    
                        print("Couldn't set Audio session category")
                    }
                } else{
                    print("not granted")
                }
            })
        }
    

提交回复
热议问题