我在Apple应用商店上有一个测验应用。问题存储在Plist文件中。我想要做的是找到一种方法,可以通过下载新版本来更新Plist文件,而不必每次有新问题要提交时都提交更新
有谁知道可以帮助我的体面的教程?
非常感谢。
我不确定教程,但是实现您所描述的步骤非常简单:
例如:
// Create a NSURL to your data
NSString *dataPath = @"www.mydata.com/path";
NSURL *dataURL = [NSURL URLWithString:dataPath];
// Create an asycnhronous request along with a block to be executed when complete
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:dataURL]
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if (error) {
NSLog(@"%@", error.localizedDescription);
// Handle the request error
}
else {
// We have some data, now we need to serialize it so that it's usable
NSError *serializationError;
NSDictionary *serializedDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&serializationError];
if (serializationError) {
NSLog(@"%@", serializationError.localizedDescription);
// Handle the serialization error
}
else {
// We have a serialized NSDictionary, now we just want to write it
// First we create the path to write it to, eg. uers documents directory
NSURL *documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
// Then write it
BOOL success = [serializedDictionary writeToFile:documentsDirectory.path atomically:YES];
if (!success) {
NSLog(@"Error writing file");
}
}
}
}];
注意:您可能需要考虑将数据存储在像Parse这样的远程数据库中。这样,您可以查询新问题,而仅下载新问题,这样就不会占用不必要的带宽。您可能还需要考虑Core Data
用于维护本地数据,而不是将其写入plist。主要优点是您不必将整个plist序列化到内存中即可使用它-您只需查询所需的特定问题即可。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句