照片和相机权限不会显示在隐私设置中

时间:2015-12-09 10:48:50

标签: ios swift privacy

我已经为照片和相机的授权创建了我的代码,但出于某种原因代码运行但从未在隐私设置中显示。我显然遗漏了一些东西,但我一直在努力研究它近12个小时而且找不到它。是否有一个清单需要在隐私设置中显示权限之前勾选所有选项。

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.Authorized {

        PHPhotoLibrary.requestAuthorization({(status: PHAuthorizationStatus) in

            let settings = NSURL(string: UIApplicationOpenSettingsURLString)

            // Create the alert controller
            let alertController = UIAlertController(title: "Access Photos", message: "ClubVIP requires access to your Photos, please enable access in Privacy Settings.", preferredStyle: .Alert)

            // Create the actions
            let privacySettingsAction = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) {
                UIAlertAction in

                //Take to Privacy Settings
                UIApplication.sharedApplication().openURL(settings!)

            }

            let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
                UIAlertAction in
                NSLog("")
            }


            // Add the actions
            alertController.addAction(privacySettingsAction)
            alertController.addAction(cancelAction)

            // Present the controller
            self.presentViewController(alertController, animated: true, completion: nil)

        })
    }

    if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) != AVAuthorizationStatus.Authorized {

        let settings = NSURL(string: UIApplicationOpenSettingsURLString)
        //let settings = NSURL(string: UIApplicationOpen)

        AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { granted in

            if !granted {

                // Create the alert controller
                let alertController = UIAlertController(title: "Access Camera", message: "Access to your Camera has been denied, please enable access in Privacy Settings.", preferredStyle: .Alert)

                // Create the actions
                let privacySettingsAction = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) {
                    UIAlertAction in

                    //Take to Privacy Settings
                    UIApplication.sharedApplication().openURL(settings!)

                }


                // Add the actions
                alertController.addAction(privacySettingsAction)

                // Present the controller
                self.presentViewController(alertController, animated: true, completion: nil)

            }


        })

    }

}

0 个答案:

没有答案