imagePickerController:真实设备

时间:2017-11-03 11:58:11

标签: ios swift firebase firebase-storage

我正在使用imagePickerController来允许用户选择要上传到firebase存储的图像。以下代码在模拟器上成功但在真正的iphone设备上失败(imagePickerController函数取自firebase示例:https://github.com/firebase/quickstart-ios/blob/master/storage/StorageExampleSwift/ViewController.swift

func imagePickerController(_ picker: UIImagePickerController,
                           didFinishPickingMediaWithInfo info: [String : Any]) {
    picker.dismiss(animated: true, completion:nil)


    // if it's a photo from the library, not an image from the camera
    if #available(iOS 8.0, *), let referenceUrl = info[UIImagePickerControllerReferenceURL] as? URL {
        let assets = PHAsset.fetchAssets(withALAssetURLs: [referenceUrl], options: nil)
        let asset = assets.firstObject
        asset?.requestContentEditingInput(with: nil, completionHandler: { (contentEditingInput, info) in
            let imageFile = contentEditingInput?.fullSizeImageURL
            let filePath = "/\(Int(Date.timeIntervalSinceReferenceDate * 1000))/\(imageFile!.lastPathComponent)"
            // [START uploadimage]
            self.storageRef.child(filePath)
                .putFile(from: imageFile!, metadata: nil) { (metadata, error) in
                    if let error = error {
                        print("Error uploading: \(error)")

                        return
                    }
                    self.uploadSuccess(metadata!, storagePath: filePath)
            }
            // [END uploadimage]
        })
    } else {
        guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else { return }
        guard let imageData = UIImageJPEGRepresentation(image, 0.8) else { return }

        let imagePath =
            //Auth.auth().currentUser!.uid +
        "/\(Int(Date.timeIntervalSinceReferenceDate * 1000)).jpg"
        let metadata = StorageMetadata()
        metadata.contentType = "image/jpeg"
        self.storageRef.child(imagePath).putData(imageData, metadata: metadata) { (metadata, error) in
            if let error = error {
                print("Error uploading: \(error)")

                return
            }
            self.uploadSuccess(metadata!, storagePath: imagePath)
        }
    }
}
  

2017-11-03 19:52:08.274996 + 0800 tutorist [432:82569] [Generic]创建具有未知类型的图像格式是错误的   2017-11-03 19:52:09.315968 + 0800 tutorist [432:82569]正文无法访问:/var/mobile/Media/DCIM/100APPLE/IMG_0027.PNG

     

错误Domain = NSCocoaErrorDomain Code = 257“无法打开文件”IMG_0027.PNG“,因为您无权查看它。” UserInfo = {NSURL = file:///var/mobile/Media/DCIM/100APPLE/IMG_0027.PNG,NSFilePath = / var / mobile / Media / DCIM / 100APPLE / IMG_0027.PNG,NSUnderlyingError = 0x170852ab0 {Error Domain = NSPOSIXErrorDomain Code = 1“不允许操作”}}   上传错误:错误域= FIRStorageErrorDomain代码= -13000“发生未知错误,请检查服务器响应。” UserInfo = {bucket = tutorism-47c98.appspot.com,object = photo / 531402728533 / IMG_0027.PNG,NSURL = file:///var/mobile/Media/DCIM/100APPLE/IMG_0027.PNG,NSLocalizedDescription =发生未知错误,请检查服务器响应。,ResponseErrorDomain = NSCocoaErrorDomain,NSFilePath = / var / mobile / Media / DCIM / 100APPLE / IMG_0027.PNG,NSUnderlyingError = 0x170852ab0 {Error Domain = NSPOSIXErrorDomain Code = 1“操作不允许”},ResponseErrorCode = 257 }

0 个答案:

没有答案