这是我在信息plist中的内容
密钥:隐私 - 相机使用说明
价值:被驱逐者想要访问你的照片
关键:隐私 - 照片库使用说明
价值:被驱逐者想要访问你的照片
此操作表的代码和选择图像后
@IBAction func didtapc(_ sender: UITapGestureRecognizer) {
let myactionsheet = UIAlertController(title : "profile picture",message:"select",preferredStyle:UIAlertControllerStyle.actionSheet)
let viewpic = UIAlertAction(title:"view pic",style: UIAlertActionStyle.default) { (action) in
let imageview = sender.view as! UIImageView
let newimageview = UIImageView(image: imageview.image)
newimageview.frame = self.view.frame
newimageview.backgroundColor = UIColor.black
newimageview.contentMode = .scaleAspectFit
newimageview.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(self.dismissaction))
newimageview.addGestureRecognizer(tap)
self.view.addSubview(newimageview)
}
let photogallery = UIAlertAction(title:"photos",style: UIAlertActionStyle.default) { (action) in
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum))
{
self.imagepicker.delegate = self
self.imagepicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum
self.imagepicker.allowsEditing = true
self.present(self.imagepicker , animated: true, completion: nil)
self.present(self.imagepicker,animated:true,completion:nil)
}
}
let camera = UIAlertAction(title:"camera",style: UIAlertActionStyle.default) { (action) in
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
{
self.imagepicker.delegate = self
self.imagepicker.sourceType = UIImagePickerControllerSourceType.camera
self.imagepicker.allowsEditing = true
self.present(self.imagepicker, animated: true, completion: nil)
}
}
myactionsheet.addAction(viewpic)
myactionsheet.addAction(photogallery)
myactionsheet.addAction(camera)
myactionsheet.addAction(UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel, handler: nil ))
self.present(myactionsheet, animated: true, completion: nil)
}
func dismissaction(sender:UITapGestureRecognizer)
{
sender.view?.removeFromSuperview()
}
func imagepickercontroller( picker : UIImagePickerController, didfinishpickingimage
image:UIImage, editinginfo: [String : AnyObject]?) {
setpc(imageView: self.pc, imageToset: image)
if let imageData: Data = UIImagePNGRepresentation(self.pc.image!)! {
let picref = datbasestorage.child("users/\(self.loggedinuser!.uid)/pc")
let uploadtask = picref.put(imageData,metadata: nil)
{ metadata,error in
if (error == nil)
{
let downloadurl = metadata!.downloadURL()
self.databaseref.child("users").child(self.loggedinuser!.uid).child("pc").setValue(downloadurl!.absoluteString)
}
else
{
print(error?.localizedDescription)
}
}
}
self.dismiss(animated: true, completion: nil)
}
}