简体   繁体   English

Swift iOS 9应用不在设置中

[英]swift ios 9 app not in Settings

I had swift camera code that worked on ios 8 and xcode 6. I called AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) but my application does not show up in Settings -> privacy -> Camera (but other apps show up) 我有可在ios 8和xcode 6上使用的快速相机代码。我叫AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),但我的应用程序未显示在“设置”->“隐私”->“相机”中 (但其他应用程序却显示了) 相机

After updating to ios 9 and xcode 7 Can't get camera permission work. 更新到ios 9和xcode 7后无法获得摄像机许可。 I searched 2 days on google and stackoverflow. 我在Google和stackoverflow上搜索了2天。


problem 问题

I imported AVFoundation and called AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) always get AVAuthorizationStatus.Denied 我导入了AVFoundation并称为AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)始终获得AVAuthorizationStatus.Denied

  1. my application does not show up in Settings -> privacy -> Camera 我的应用程序未显示在“设置”->“隐私”->“相机”中
  2. Camera is black 相机是黑色的
  3. requestAccessForMediaType does not open popup requestAccessForMediaType不打开弹出窗口
  4. authorizationStatusForMediaType is always Denied authorizationStatusForMediaType始终被拒绝

Main problem is No 1. I think if I can get my app on Settings -> privacy -> Camera then other problems are solved. 主要问题是1。我想如果我可以在“设置”->“隐私”->“相机”上获取我的应用,那么其他问题就可以解决。

thigns I tried 我尝试过的

  • child class of UIImagePickerController UIImagePickerController的子类
  • Removed and reinstalled my app 删除并重新安装了我的应用
  • Changed Bundle ID 更改捆绑ID
  • Changed iphone date to 3 days in future 将iPhone日期更改为未来3天
  • called requestAccessForMediaType in main thread 在主线程中称为requestAccessForMediaType

  • Xcode 7 Xcode 7
  • ios 9.0 9.1 的iOS 9.0 9.1
  • iphone 5, 5s, 6 iPhone 5、5S,6
  • swift 2.1 迅捷2.1

my code 我的密码

override func viewDidLoad() {
    super.viewDidLoad()
        cameraView()
}

func checkCamera() {
        let authStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
        switch authStatus {
        case AVAuthorizationStatus.Authorized:
            print("AVAuthorizationStatus.Authorized")
        case AVAuthorizationStatus.Denied:
            print("AVAuthorizationStatus.Denied")
        case AVAuthorizationStatus.NotDetermined:
            print("AVAuthorizationStatus.NotDetermined")
        case AVAuthorizationStatus.Restricted:
            print("AVAuthorizationStatus.Restricted")
        default:
            print("AVAuthorizationStatus.Default")
        }

    }

func cameraView(){
        // session
        let mySession : AVCaptureSession = AVCaptureSession()
        var myDevice : AVCaptureDevice? //= AVCaptureDevice()
        let myImageOutput : AVCaptureStillImageOutput = AVCaptureStillImageOutput()
        let devices = AVCaptureDevice.devices()

        let audioCaptureDevice = AVCaptureDevice.devicesWithMediaType(AVMediaTypeAudio)
        let audioInput = (try! AVCaptureDeviceInput(device: audioCaptureDevice[0] as! AVCaptureDevice))  as AVCaptureInput

        for device in devices {
            if(device.position == AVCaptureDevicePosition.Back){
                myDevice = device as? AVCaptureDevice
            }
        }

        let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
        print(status ==  AVAuthorizationStatus.Authorized)
        print(status ==  AVAuthorizationStatus.Denied)
        print(status ==  AVAuthorizationStatus.Restricted)
        print(status.rawValue)

        if status !=  AVAuthorizationStatus.Authorized {

            AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
                if granted == false {
                    // Camera not Authorized
                    dispatch_async(dispatch_get_main_queue()) {
                        print("Camera not Authorized")
                        self.checkCamera()
                        return
                    }
                }
            });
        }

You need to set a new pair of Info.plist values, same as the String for Location Services would be in iOS8: 您需要设置一对新的Info.plist值,与iOS8中的定位服务字符串相同:

Just set your description string for those. 只需为它们设置描述字符串即可。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM