Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 当我在UIActivityViewController中调用对PHPhotoLibrary的请求权限时,它会调用两次_Swift_Phphotolibrary - Fatal编程技术网

Swift 当我在UIActivityViewController中调用对PHPhotoLibrary的请求权限时,它会调用两次

Swift 当我在UIActivityViewController中调用对PHPhotoLibrary的请求权限时,它会调用两次,swift,phphotolibrary,Swift,Phphotolibrary,我创建了UIActivityViewController,并检查选择了哪种共享类型。我需要保存在我的照片库中,并选中.saveToCameraRoll。如果我没有在activityVC.completionWithItemsHandler中调用PHPhotoLibrary.requestAuthorization,那么它总是返回类似.notDetermined的状态,并显示一次权限请求。当我在CAomplionHandler中调用PHPhotoLibrary.requestAuthorizati

我创建了
UIActivityViewController
,并检查选择了哪种共享类型。我需要保存在我的照片库中,并选中
.saveToCameraRoll
。如果我没有在
activityVC.completionWithItemsHandler
中调用
PHPhotoLibrary.requestAuthorization
,那么它总是返回类似
.notDetermined
的状态,并显示一次权限请求。当我在CAomplionHandler中调用
PHPhotoLibrary.requestAuthorization
时,它会显示两次权限警报,当我在第二次警报中允许访问时,我可以按预期检查状态。 我的代码:


如果PHPhotoLibrary.authorizationStatus()!=,为什么要执行
。授权的
,并且不使用您在完成块中禁用的参数?如果用户拒绝访问库,我将显示应用程序需要它来保存屏幕快照的警报。我的意思是它不应该是
PHPhotoLibrary.requestAuthorization({status in if status!=.authorized{//此处我显示警报})
而不是
PHPhotoLibrary.requestAuthorization({in if PHPhotoLibrary.authorizationStatus()!=.authorized{//这里我显示警报}}})
好的观点。但在我第一次尝试这样做时,它仍然会两次请求权限
activityVC.completionWithItemsHandler={activity,success,items,error in guard activity==.saveToCameraRoll else{return}如果PHPhotoLibrary.authorizationStatus()!=.authorized{//此处我显示警报}}
但如果我拒绝访问并再次尝试保存,则不会显示正确的状态

        let sourceRect = rect ?? CGRect(x: frame.minX, y: frame.maxY - 1, width: frame.width, height: 1)

        activityVC.modalPresentationStyle = .popover
        activityVC.popoverPresentationController?.sourceRect = sourceRect
        activityVC.popoverPresentationController?.sourceView = viewController?.view

        activityVC.completionWithItemsHandler = { activity, success, items, error in
            guard activity == .saveToCameraRoll else { return }
            PHPhotoLibrary.requestAuthorization({ _ in
                if PHPhotoLibrary.authorizationStatus() != .authorized {
                    //here I show alert 
                }
            })
        }

        viewController?.present(activityVC, animated: true, completion: nil)```