ios - Unable to get devices using AVCaptureDevice -


i've managed find code give me access devices of phone (such camera). issue when compile code (and i'm printing different devices) using xcode, empty array.

here wrote:

import uikit import avfoundation  class viewcontroller: uiviewcontroller {    let capturesession = avcapturesession()   var previewlayer : avcapturevideopreviewlayer?    // if find device we'll store here later   var capturedevice : avcapturedevice?    override func viewdidload() {     super.viewdidload()                 // additional setup after loading view, typically nib.      capturesession.sessionpreset = avcapturesessionpresethigh      let devices = avcapturedevice.devices()     println(devices)     // loop through capture devices on phone     (device in devices) {         // make sure particular device supports video         if (device.hasmediatype(avmediatypevideo)) {          // check position , confirm we've got camera             if(device.position == avcapturedeviceposition.back) {                 capturedevice = device as? avcapturedevice                 if capturedevice != nil {                     println("capture device found")                     beginsession()                 }             }         }       }      }      func beginsession() {        var err : nserror? = nil       capturesession.addinput(avcapturedeviceinput(device: capturedevice, error: &err))        if err != nil {           println("error: \(err?.localizeddescription)")       }        previewlayer = avcapturevideopreviewlayer(session: capturesession)       self.view.layer.addsublayer(previewlayer)       previewlayer?.frame = self.view.layer.frame        capturesession.startrunning()      }    } 

do have ideas why getting empty array?

if you're running in simulator, array empty because has no physical hardware choose from. in fact, if try access physical hardware inside simulator, crash. if plug device in , still empty array, let me know.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -