1. 程式人生 > >iOS錄音,呼叫麥克風話筒

iOS錄音,呼叫麥克風話筒

AVAudioSession.sharedInstance().requestRecordPermission({ [weak self] (granted) in
                guard let w = self else {
                    return
                }
                if !granted {
                    let alert = UIAlertController(title: "沒有麥克風許可權", message: "請在iPhone的“設定-隱私-麥克風”選項中,允許你的醫生訪問麥克風。", preferredStyle: .Alert)
                    let jumpToSetting = UIAlertAction(title: "去設定", style: .Default, handler: { (sender) in
                        UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
                        alert.dismissViewControllerAnimated(true, completion: nil)
                    })
                    alert.addAction(jumpToSetting)
                    let cancel = UIAlertAction(title: "取消", style: .Cancel, handler: { (sender) in
                        alert.dismissViewControllerAnimated(true, completion: nil)
                    })
                    alert.addAction(cancel)
                    w.presentViewController(alert, animated: true, completion: nil)
                } else {
                    //獲取許可權成功
                }
            })