2016-06-27 11 views
1

@IBAction의 FUNC의 shareButton (보낸 사람 : AnyObject) {스위프트 중포 기지 파일 업로드

//Social Share Buttons.. 

     let shareActionsheet = UIAlertController(title: "Share with", message: nil, preferredStyle: .ActionSheet) 
    //Facebook 
    let Facebook = UIAlertAction(title: "Facebook", style: .Default){(Alert:UIAlertAction!) -> Void in 
    let shareFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook) 
     //screenShot 
     UIGraphicsBeginImageContextWithOptions(CGSizeMake(306, 441.5), false, 0) 
     self.view.drawViewHierarchyInRect(CGRectMake(-35, -35, self.view.bounds.size.width, self.view.bounds.size.height), afterScreenUpdates: true) 
     let image:UIImage = UIGraphicsGetImageFromCurrentImageContext() 
     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) 
     //screenShot finish 

// CREAT 스크린 샷 이미지
//shareFacebook.addImage(image는)

 self.presentViewController(shareFacebook, animated: true, completion: nil) 


     if let user = FIRAuth.auth()?.currentUser{ 



     //dosya upload - servise referans sağla.. 
     let storage = FIRStorage.storage() 

     //referans yolu 
     let storageRef = storage.referenceForURL("gs://creawo-80503.appspot.com") 

     let data: NSData = NSData() 
     // Create a reference to the file you want to upload 
     let riversRef = storageRef.child("\(self.user!.uid+"/share_pic.jpg")/") 

     // Upload the file to the path "images/rivers.jpg" 
     let uploadTask = riversRef.putData(data, metadata: nil) { metadata, error in 
      if (error != nil) { 
       // Uh-oh, an error occurred! 
      } else { 

나는 경로를 보여 주었다 및 파일 생성. 경고가 이미지에서 스크린 샷을 찍고 있습니다. firebase를 설치하고 싶습니다. // 메타 데이터에는 크기, 내용 유형 및 다운로드 URL과 같은 파일 메타 데이터가 포함되어 있습니다.

I couldn't find a solution about this place   
let downloadURL = metadata!.downloadURL() 
      } 
     } 

}

답변

0
@IBAction func postAd(sender: AnyObject) { 
    self.name = self.textField.text! 
    self.category = (self.chooseButton.titleLabel?.text)! 
    self.subcat = self.subcategory.text! 

    if (self.name != "" && self.category != "" && self.subcat != ""){ 

     self.price = Int(self.priceField.text!)! 
     self.transaction = (self.transactionButton.titleLabel?.text 
     )! 

     let book = ["productId": self.productId, 
        "name": self.name, 
        "parentId": self.parentId, 
        "price": self.price, 
        "transaction":self.transaction, 
        "category":self.category, 
        "subcat":self.subcat] 
     let childUpdates = ["products/\(productId)": book] 


     let data: NSData = UIImageJPEGRepresentation(imagePreview.image!, 0.8)! 

     // Create a reference to the file you want to upload 
     let metadata = FIRStorageMetadata() 
     metadata.contentType = "image/jpeg" 
     // Upload the file to the path "images/rivers.jpg" 
     let uploadTask = storageRef.child("\(productId)").putData(data, metadata: nil) { metadata, error in 
      if (error != nil) { 
       // Uh-oh, an error occurred! 
       print("Error") 
      } else { 
       print("Successfully posted") 
       // Metadata contains file metadata such as size, content-type, and download URL. 
       let downloadURL = metadata!.downloadURL() 
       print(downloadURL) 
      } 
     } 
     print(uploadTask) 


     self.ref.updateChildValues(childUpdates) 

     self.performSegueWithIdentifier("productToHome", sender: self) 
    } 
    else{ 
     let alert:UIAlertController = UIAlertController(title: "Fill all details", message: "Please Enter all details", preferredStyle: UIAlertControllerStyle.Alert) 
     alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
     self.presentViewController(alert, animated: true, completion: nil) 
     print("Fill all the details") 
    } 
} 

나는 내 데이터베이스에있는 책의 내용을 업로드하고 있습니다. 'metadata'부분은 내가 사용한 것처럼 사용할 수 있습니다. 'imagePreview'는 imagePicker에서 선택한 이미지를 포함합니다. 이미지를 선택하는 기능은 다음과 같습니다.

//Internal function to select image and preview it in Image View 
// MARK: - UIImagePickerControllerDelegate Methods 
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo editingInfo: [String : AnyObject]) { 
    if let pickedImage = editingInfo[UIImagePickerControllerOriginalImage] as? UIImage { 
     imagePreview.contentMode = .ScaleAspectFit 
     imagePreview.image = pickedImage 
    } 
    dismissViewControllerAnimated(true, completion: nil) 
} 

func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
    dismissViewControllerAnimated(true, completion: nil) 
} 
//Image Viewer Ends 
+0

감사합니다. Bharat : +100 –

+0

@ OğuzMuslu 답장을 보내지 마십시오. 문제가 해결되면 답변을 올바르게 설정하십시오. –