【发布时间】:2016-11-14 23:50:56
【问题描述】:
我正在尝试从连接到 Heroku 上托管的 Parse Server 实例的 MongoDB 数据库中获取 PFFile。
我保存了文件,所以(文件
var post = PFObject(className: "Posts")
let imageData = UIImageJPEGRepresentation(UIImage(named: "post_two")!, 0.5)
post["picImage"] = PFFile(name: "post_two.jpg", data: imageData!)
post["username"] = "example"
post["title"] = "welcome"
post["info"] = "Thanks"
post.saveInBackgroundWithBlock { (success:Bool?, error:NSError?) in
if (success != nil && success == true)
{
print("post registred")
}
else{
print(error!.localizedDescription)
}
}
然后我加载了帖子:
let elements = PFQuery(className: "Posts")
elements.findObjectsInBackgroundWithBlock ({ (objects:[PFObject]?, error:NSError?) -> Void in
if error == nil
{
for object in objects!
{
//add found data to arrays (holders)
let imagesQuery = object.valueForKey("picImage") as! PFFile
picArray.append(imagesQuery)
}
}
else
{
print((error?.localizedDescription)! + "load post")
}
})
问题出在这里:
picArray[i].getDataInBackgroundWithBlock { (data:NSData?, error:NSError?) -> Void in
if error == nil
{
picImg.image = UIImage(data: data!)
}
else
{
print((error?.localizedDescription)!)
}
}
错误是:网络连接失败。在休眠 13.835050 秒后尝试 4。 [错误]:不支持的 URL(代码:100,版本:1.12.0)不支持的 URL
在 DEBUG 中,getDataInBackgroundWithBlock 中的数据为 NiL。我不知道问题是文件存储、加载还是应用程序传输安全设置(在某些帖子中,有些建议包含例外域,我已经正确插入,但没有任何改变)。
非常感谢,我不知道在哪里可以找到解决方案
【问题讨论】:
标签: swift xcode mongodb heroku parse-platform