最终使用 PFFile(解析本地数据存储)保存在 PFObject 上?
Save eventually on PFObject with PFFile (Parse Local Datastore)?
目标
我正在尝试保存具有 PFFile
作为属性的 PFObject
。我正在为 iOS 使用新的 Local Datastore,所以我想用 saveEventually()
方法保存这个 PFObject
。
问题
我遇到的问题是 saveEventually()
方法似乎不喜欢保存 PFFiles
。我尝试 saveEventually()
我的对象,但没有附加任何 PFFile
,效果很好。一旦我的 PFFile
被重新连接,Xcode 抛出了几个断点通知(错误?)但没有终止应用程序,看起来一切顺利 - 但是检查解析数据浏览器确认保存没有通过。
在本地数据存储功能之前,我不相信这种保存是可能的 - 它会抛出 "Unable to saveEventually a PFObject with a relation to a new, unsaved PFFile."
错误。似乎本地数据存储功能已经解决了这个问题,正如它在 iOS Local Datastore docs 中所述:
"Pinning a PFObject is recursive, just like saving, so any objects
that are pointed to by the one you are pinning will also be pinned.
When an object is pinned, every time you update it by fetching or
saving new data, the copy in the local datastore will be updated
automatically. You don't need to worry about it at all."
我已经将SDK更新到最新版本(v1.6.2)。有任何想法吗?
PFFiles 仍然不支持 saveEventually
see here
该页面的最后更新时间:2015-01-23
您可以pinInBackgroundWithBlock
,如果成功将 PFFile 保存到应用程序包中的临时文件夹,并在必要时或取消固定时将其删除
我刚刚发布了一个 class,它允许最终保存一个 PFFile。
你可以找到它 here :
/*
This example uses an UIImage, but this works with any file writable as NSData
We begin by writing this image in our tmp directory with an uuid as name.
*/
UIImage *nyancat = [UIImage imageNamed:@"nyancat.jpg"];
NSData *imageData = UIImageJPEGRepresentation(nyancat, 0.5);
NSString *filename = [[NSUUID UUID] UUIDString];
NSURL *fileUrl = [PFFileEventuallySaver fileURLInTmpWithName:filename];
[imageData writeToURL:fileUrl atomically:YES];
/*
We create a PFObject (you can pass an array to below function if you need your file to be saved on several objects). If upload works on first time, do what you want with your file, like linking it on your PFobject.
If saving fails, it'll be retried as soon as network is available, on this session or nexts launches of app.
In that case, the pointer at key kPFFILE_MANAGER_OBJECT_FILE_KEY of your PFFObject will be set with the PFFile, then saved eventually within PFFileEventuallySaver
*/
PFObject *object = [PFObject objectWithClassName:kPFFILE_CONTAINER_OBJECT_CLASSNAME];
[[PFFileEventuallySaver getInstance] trySaveobjectAtURL:fileUrl associatedObjects:@[object] withBlock:^(PFFile *file, NSError *error) {
if(!error)
{
NSLog(@"[First try, network is fine] File saved, saving PFObject");
object[kPFFILE_MANAGER_OBJECT_FILE_KEY] = file;
[object saveEventually];
NSLog(@"Try again disabling your network connection");
}
else
{
NSLog(@"No network, connect back your wifi, or relaunch app. Your file will be sent");
}
} progressBlock:^(int percentDone) {
NSLog(@"[First try, network is fine] Sending file %d/100%%", percentDone);
}];
目标
我正在尝试保存具有 PFFile
作为属性的 PFObject
。我正在为 iOS 使用新的 Local Datastore,所以我想用 saveEventually()
方法保存这个 PFObject
。
问题
我遇到的问题是 saveEventually()
方法似乎不喜欢保存 PFFiles
。我尝试 saveEventually()
我的对象,但没有附加任何 PFFile
,效果很好。一旦我的 PFFile
被重新连接,Xcode 抛出了几个断点通知(错误?)但没有终止应用程序,看起来一切顺利 - 但是检查解析数据浏览器确认保存没有通过。
在本地数据存储功能之前,我不相信这种保存是可能的 - 它会抛出 "Unable to saveEventually a PFObject with a relation to a new, unsaved PFFile."
错误。似乎本地数据存储功能已经解决了这个问题,正如它在 iOS Local Datastore docs 中所述:
"Pinning a PFObject is recursive, just like saving, so any objects that are pointed to by the one you are pinning will also be pinned. When an object is pinned, every time you update it by fetching or saving new data, the copy in the local datastore will be updated automatically. You don't need to worry about it at all."
我已经将SDK更新到最新版本(v1.6.2)。有任何想法吗?
PFFiles 仍然不支持 saveEventually
see here
该页面的最后更新时间:2015-01-23
您可以pinInBackgroundWithBlock
,如果成功将 PFFile 保存到应用程序包中的临时文件夹,并在必要时或取消固定时将其删除
我刚刚发布了一个 class,它允许最终保存一个 PFFile。
你可以找到它 here :
/*
This example uses an UIImage, but this works with any file writable as NSData
We begin by writing this image in our tmp directory with an uuid as name.
*/
UIImage *nyancat = [UIImage imageNamed:@"nyancat.jpg"];
NSData *imageData = UIImageJPEGRepresentation(nyancat, 0.5);
NSString *filename = [[NSUUID UUID] UUIDString];
NSURL *fileUrl = [PFFileEventuallySaver fileURLInTmpWithName:filename];
[imageData writeToURL:fileUrl atomically:YES];
/*
We create a PFObject (you can pass an array to below function if you need your file to be saved on several objects). If upload works on first time, do what you want with your file, like linking it on your PFobject.
If saving fails, it'll be retried as soon as network is available, on this session or nexts launches of app.
In that case, the pointer at key kPFFILE_MANAGER_OBJECT_FILE_KEY of your PFFObject will be set with the PFFile, then saved eventually within PFFileEventuallySaver
*/
PFObject *object = [PFObject objectWithClassName:kPFFILE_CONTAINER_OBJECT_CLASSNAME];
[[PFFileEventuallySaver getInstance] trySaveobjectAtURL:fileUrl associatedObjects:@[object] withBlock:^(PFFile *file, NSError *error) {
if(!error)
{
NSLog(@"[First try, network is fine] File saved, saving PFObject");
object[kPFFILE_MANAGER_OBJECT_FILE_KEY] = file;
[object saveEventually];
NSLog(@"Try again disabling your network connection");
}
else
{
NSLog(@"No network, connect back your wifi, or relaunch app. Your file will be sent");
}
} progressBlock:^(int percentDone) {
NSLog(@"[First try, network is fine] Sending file %d/100%%", percentDone);
}];