iOS网络编程
来源:互联网 发布:淘宝店铺突然不存在了 编辑:程序博客网 时间:2024/06/11 22:22
iCloud文档在保存的过程中难免会发生冲突,我们必须要有一套解决冲突的策略。策略的采用要根据用户的需求而定,有的简单有的复杂,最简单的是 直接使用当前版本覆盖冲突版本。复杂的策略,例如:如果是两个文本文件冲突,可以将两个冲突点列出来,让用户来判断再进行保存。
我们采用的策略是使用当前版本覆盖以前的版本。解决冲突首先需要在updateUbiquitousDocuments:方法中注册UIDocumentStateChangedNotification通知:
//当iCloud中的文件变化时候调用- (void)updateUbiquitousDocuments:(NSNotification *)notification {… …if (_myCloudDocument) {//注册CloudDocument对象到文档协调者,文档状态变化才能收到通知[NSFileCoordinator addFilePresenter:_myCloudDocument]; ①//注册文档状态变化通知[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resolveConflict:)name:UIDocumentStateChangedNotification object:nil]; ②}}//文档冲突解决- (void)resolveConflict:(NSNotification *)notification {if (_myCloudDocument&& _myCloudDocument.documentState == UIDocumentStateInConflict) { ③NSLog(@”冲突发生”);//文档冲突解决策略NSError *error;if (![NSFileVersion removeOtherVersionsOfItemAtURL: _myCloudDocument.fileURL error:&error]) { ④NSLog(@”移除其它的文档: %@”, [error localizedFailureReason]);return;}_myCloudDocument.contents = _txtContent.text; ⑤[_myCloudDocument updateChangeCount:UIDocumentChangeDone]; ⑥}[[NSNotificationCenter defaultCenter] removeObserver:selfname:UIDocumentStateChangedNotification object:nil]; ⑦//从文档协调者中解除CloudDocument对象[NSFileCoordinator removeFilePresenter:_myCloudDocument]; ⑧}
出自《iOS网络编程与云端应用最佳实践》作者:关东升 @tony_关东升
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- iOS网络编程总结
- iOS网络编程总结
- ios网络编程
- ios网络编程
- IOS网络编程
- ios网络编程
- IOS网络编程介绍
- ios网络编程
- ios 网络编程总结
- ios网络编程
- IOS 网络编程总结
- iOS 网络编程小结
- iOS网络编程总结
- iOS 网络编程摘要
- IOS网络编程:HTTP
- iOS网络编程
- iOS网络编程
- iOS网络编程
- python发送邮件简单示例
- UML图之四——活动图
- 面试题集锦
- ubuntu 8.04下java语言开发的搭建
- 在word中替换“记事本”文件中的自动换行符
- iOS网络编程
- NSTimer与UITableView同时使用
- enummap 使用示例
- java.lang.ArrayIndexOutOfBoundsException异常分析及解决
- VS2010 与IE10的Debug冲突解决方案
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据
- enumset和enummap使用示例
- C Traps and Pitfalls (C语言陷阱和缺陷) 读书总结
- Android之Adapter用法总结