2017-12-09 15 views
0

私は自分のアプリに写真ピッカーを実装しようとしています。何らかの理由で、次の2つのエラーが発生します。タイプ 'StorageReference'の値にメンバー 'データ'がありません。タイプ 'StorageReference'の値にメンバー 'put'がありません。ここに私のコードです。私は正直なところ、問題がどんなものか分かりません。どんな入力も非常に高く評価されます。ありがとう。タイプ 'StorageReference'の値にメンバー 'データ'はありませんか?

import UIKit 

import FirebaseStorage 
import Photos 
class AlbumViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 

    var id: String = "" 
let picker = UIImagePickerController() 

    @IBOutlet weak var image1: UIImageView! 
    let storage = Storage.storage() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.title = id 
     picker.delegate = self as! UIImagePickerControllerDelegate & UINavigationControllerDelegate 
     showPhoto() 

     // Do any additional setup after loading the view. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    //confirm 
    func confirm() { 
     let myAlert = UIAlertController(title: "Firebase Storage", message: "Image Uploaded", preferredStyle: UIAlertControllerStyle.alert) 
     myAlert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: nil)) 
     self.present(myAlert, animated: true, completion: nil) 
    } 


    //retrive pictures 
    @IBAction func accessAlbum(_ sender: UIBarButtonItem) { 

     picker.allowsEditing = false 
     picker.sourceType = .photoLibrary 
     picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! 
     picker.modalPresentationStyle = .popover 
     present(picker, animated: true, completion: nil) 
     picker.popoverPresentationController?.barButtonItem = sender 

    } 
    //for image size 
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
     print(info) 

     var selectedImageFromPicker: UIImage? 

     if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage 
     { 
      selectedImageFromPicker = editedImage 
     }else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage{ 
      selectedImageFromPicker = originalImage 
     } 

     if let selectedImage = selectedImageFromPicker 
     { 
      image1.image = selectedImage.resizedImageWithinRect(rectSize: CGSize(width: 300, height: 300)) 
      image1.contentMode = .scaleAspectFit //3 

     } 
     dismiss(animated: true, completion: nil) 
    } 




    @IBAction func savePic(_ sender: Any) { 
     var data = Data() 
     data = UIImagePNGRepresentation(image1.image!)! as Data 
     // set upload path 
     let imageName = "Photos/" + id + ".png" 

     // ---- Upload the image to firebase storage 
     let storageRef = storage.reference(withPath: imageName) 
     let metaData = StorageMetadata() 
     metaData.contentType = "image/png" 
     storageRef.put(data, metadata: metaData){(metaData,error) in //ERROR HERE 
      if let error = error { 
       print(error.localizedDescription) 
       return 
      }else{ 
       self.confirm() 
      } 
     } 
    } 

    func showPhoto() { 
     let imageName = "Photos/" + id + ".png" 

     // Create a storage reference path with image name 

     let storageRef = storage.reference(withPath: imageName) 

     storageRef.data(withMaxSize: 3 * 1024 * 1024) { (data, error) // ERROR HERE-> Void in 
      // Create a UIImage, add it to the array 
      if let imgData = data { 
       let image = UIImage(data: imgData) 

       DispatchQueue.main.async { 
        self.myImageView.image = image 
       } 
       // 

      } else { 
       print ("no image data") 
      } 

     } 
    } 






} 
extension UIImage { 

    /// Returns a image that fills in newSize 
    func resizedImage(newSize: CGSize) -> UIImage { 
     // Guard newSize is different 
     guard self.size != newSize else { return self } 

     UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0); 
     // self.drawInRect(CGRect(0, 0, newSize.width, newSize.height)) 
     self.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)) 
     let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()! 
     UIGraphicsEndImageContext() 
     return newImage 
    } 

    /// Returns a resized image that fits in rectSize, keeping it's aspect ratio 
    /// Note that the new image size is not rectSize, but within it. 
    func resizedImageWithinRect(rectSize: CGSize) -> UIImage { 
     let widthFactor = size.width/rectSize.width 
     let heightFactor = size.height/rectSize.height 

     var resizeFactor = widthFactor 
     if size.height > size.width { 
      resizeFactor = heightFactor 
     } 

     let newSize = CGSize(width: size.width/resizeFactor, height: size.height/resizeFactor) 

     // CGSize(size.width/resizeFactor, size.height/resizeFactor) 
     let resized = resizedImage(newSize: newSize) 
     return resized 
    } 

} 

答えて

0

StorageReferenceputまたはdataと呼ばれるメソッドはありません。

おそらくputDatagetDataを使用しようとしていましたか?

+0

文字通り、ここで確認する前にそれを試しました。それはそれをするように見えました。ありがとう! – Justin

関連する問題