在一个iOS应用程序中,我试图以一种新的方式(对我而言)使用Parse.com。我想存储一旦inApp购买完成,用户就可以使用的数据。
我已经到了点,我可以把一个虚拟文件在服务器上,并把它到我的应用程序,一旦购买完成。但是我的问题来了:我应该在Parse.com上上传什么样的文件?通过反复试验,我注意到一个简单的文本(.txt)文件无法工作,而.png或.zip似乎是工作扩展。内容似乎无关紧要。我也读过它必须是一个文件。因此,如果我想让我的用户获得一些文本,一些声音和图片,我显然必须将其打包到一个文件中,并在下载后解压。我应该放置一个.zip文件或其他压缩格式吗?然后如何在下载后解压缩?例如,假设我希望用户获得:
我该怎么走?欢迎一些示例代码或教程指示。谢谢你的帮助。
发布于 2015-02-20 13:27:41
根据文档,只要文件不超过10 As,就可以保存任何二进制数据。
“最常见的用例是存储图像,但也可以将其用于文档、视频、音乐和任何其他二进制数据(高达10兆字节)。”
下面是上传三个文本文件的示例。为了简单起见,我有一个名为TestClass的类,它的文件类型为File1、File2和File3。
对于每个文件,我们将使用saveInBackgroundWithBlock方法,因此我们知道我们的文件何时保存成功,并且可以将它与适当的TestClass列关联起来。
PFObject *testClass = [PFObject objectWithClassName:@"TestClass"];
NSData *data = [@"This is the first text file!" dataUsingEncoding:NSUTF8StringEncoding];
PFFile *file = [PFFile fileWithName:@"file1.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
testClass[@"File1"] = file;
[testClass saveInBackground];
}
}];
data = [@"This is the second text file!" dataUsingEncoding:NSUTF8StringEncoding];
file = [PFFile fileWithName:@"file2.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
testClass[@"File2"] = file;
[testClass saveInBackground];
}
}];
data = [@"This is the third text file!" dataUsingEncoding:NSUTF8StringEncoding];
file = [PFFile fileWithName:@"file3.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
testClass[@"File3"] = file;
[testClass saveInBackground];
}
}];https://stackoverflow.com/questions/28605040
复制相似问题