Firebase存储上载可在Simulator中使用,但不能在iPhone上使用 [英] Firebase storage upload works in Simulator but not on iPhone

查看:88
本文介绍了Firebase存储上载可在Simulator中使用,但不能在iPhone上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Xcode会向我抱怨有关将图像上传到Firebase Storage的权限,但是当我在Simulator中运行相同的应用程序时,它工作正常吗?

Any reason why Xcode would complain to me about permissions in regards to uploading an image to Firebase Storage but when I run the same app in the Simulator, it works fine?

权限错误:

无法访问主体文件:/var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG Error Domain = NSCocoaErrorDomain代码= 257文件"IMG_0974.JPG" 无法打开,因为您没有查看权限." UserInfo = {NSURL = file:///var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG, NSFilePath =/var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG, NSUnderlyingError = 0x14805d680 {Error Domain = NSPOSIXErrorDomain Code = 1 不允许操作"}}

Body file is unreachable: /var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG Error Domain=NSCocoaErrorDomain Code=257 "The file "IMG_0974.JPG" couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG, NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0974.JPG, NSUnderlyingError=0x14805d680 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

推荐答案

我现在遇到相同的问题.上载在Simulator中的效果很好,但是在设备上却出现了权限错误.我的解决方法是将图像作为数据而不是与文件的URL一起上传:

I'm having the same problem right now. Uploading works fine in the Simulator, but on a device it gives me the permission error. My workaround has been to upload the image as data rather than with the URL to the file:

let imageData = UIImageJPEGRepresentation(image, 1.0)
let uploadTask = storageReference.child(remoteFilePath).putData(imageData, metadata: metadata, completion: { (metadata, error) in
    // Your code here
}

这篇关于Firebase存储上载可在Simulator中使用,但不能在iPhone上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆