菜鸟教程小白 发表于 2022-12-13 05:48:14

ios - 如何在 iPhone 应用程序中更新数据


                                            <p><p>我创建了一个应用程序,数据存储在 plist 中。现在我可以通过哪些方式更新数据?也许如果我创建一个网页并从中检索我的数据而不是存储在 plist 中?或者有什么方法可以在我插入 iTunes 时更新我的​​数据?或者有什么其他建议?我想要实现的是一种在用户下载应用程序后更新我的数据的方法。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code>NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = ;
NSString *filePath = ;

NSMutableDictionary *localDictionary;
NSUrl *remoteUrl = ;
NSMutableDictionary *remoteDictionary = ;
if(remoteDictionary != nil) {
   ;
   localDictionary = remoteDictionary;
}
else {
   localDictionary = ;
   if(localDictionary == nil) localDictionary = ;
}
</code></pre>

<p>这将尝试从 <code>http://server.com/</code> 获取 <code>my.plist</code> 的副本,成功后会将其写入磁盘并指向 <code>localDictionary</code> 到它,出错时它会尝试从磁盘读取(例如,之前有连接时下载的),如果磁盘上没有文件,它将创建一个空的 <code>NSMutableDictionary</code> .无论哪种方式,<code>localDictionary</code> 最终都会指向一个 <code>NSMutableDictionary</code>。</p>

<p>这很简单,每次运行代码时都会请求文件。你可以例如使用 <code>NSFileModificationDate</code>(由 <code>NSFileManger attributesOfItemAtPath:error:</code> 获得)和 <code>NSDate</code> 来确定是否需要更新。或者对于大文件版本控制也是有意义的,拥有一个包含大文件版本的小文件 - 从服务器获取小文件(例如使用 <code>NSString</code>),检查缓存的版本文件是否包含较低的版本号,如果是这样,请获取大文件。它始终取决于内容的刷新频率。</p>

<p>查看完整文档:<a href="http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSDictionary_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">NSDictionary</a> , <a href="http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSString_Class/Reference/NSString.html" rel="noreferrer noopener nofollow">NSString</a> , <a href="http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSFileManager_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">NSFileManager</a> , <a href="http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSDate_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">NSDate</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iPhone 应用程序中更新数据,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/3581848/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/3581848/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iPhone 应用程序中更新数据