Scan functionality doesn't work on Action Extension(no camera opening to scan )

我的梦境 提交于 2020-01-07 02:56:06

问题


i am able to implement buttonactions,tableview,textfields ,switch... all are working fine in ActionExtension

BUT

Scan Functionality doesn't work (no camera opening to scan ) in Action Extension . Below i shared my scanning code in swift and screenshot of my Extension

Declarations :

var scannedBarcode = NSString(string: "")
var scannedMetadataOutput = AVCaptureMetadataOutput()

var gCaptureMetadataOutput = AVCaptureMetadataOutput()
var _prevLayer = AVCaptureVideoPreviewLayer()
var _session = AVCaptureSession()

Scan Button Action Code :

 @IBAction func scanExtenAction(sender: AnyObject) {

    scanExtAction.enabled = false


    var error:NSError? = nil
    //let _input = (try! AVCaptureDeviceInput.deviceInputWithDevice(gCaptureDevice))
    let _input = (try! AVCaptureDeviceInput.init(device: gCaptureDevice))

    if _session.canAddInput(_input)
    {
        _session.addInput(_input)
    }

    var _output = AVCaptureMetadataOutput()

    gCaptureMetadataOutput.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())

    if _session.canAddOutput(gCaptureMetadataOutput)
    {
        _session.addOutput(gCaptureMetadataOutput)
    }

    //        gCaptureMetadataOutput.metadataObjectTypes = gCaptureMetadataOutput.availableMetadataObjectTypes
    gCaptureMetadataOutput.metadataObjectTypes = gCaptureMetadataOutput.availableMetadataObjectTypes

    _prevLayer = AVCaptureVideoPreviewLayer(layer: _session) as AVCaptureVideoPreviewLayer

    //_prevLayer.frame = self.view.bounds
    //_prevLayer.frame = CGRectMake( DEVICE_WIDTH * 0.10 , DEVICE_HEIGHT * 0.10, DEVICE_WIDTH * 0.8, DEVICE_HEIGHT * 0.4 )
    _prevLayer.frame = CGRectMake(0 , 0, 280, 300 )
    _prevLayer.cornerRadius = 10


    _prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;


   self.view.layer.addSublayer(_prevLayer)


    _session.startRunning()



}


回答1:


App Extensions cannot do the following:

1.Access the camera or microphone on an iOS device.

2.Receive data using AirDrop (It can however send data using AirDrop).

3.Perform long-running background tasks.

4.Use any API marked in header files with the NS_EXTENSION_UNAVAILABLE macro, or similar unavailability macro, or any API in an unavailable framework for example EventKit and HealthKit are unavailable to app extensions.

5.Access a sharedApplication object, and so cannot use any of the methods on that object

refer below link for more info: link



来源:https://stackoverflow.com/questions/35626898/scan-functionality-doesnt-work-on-action-extensionno-camera-opening-to-scan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!