iCloud7_Next Steps

下一步Next Steps

在此次指导中,你创建了一个复杂的iOS应用,使用iCloud保存它的文档。设计一个支持 iCloud 的应用程序,涉及很多决策,即使这样,本教程只触及表面(浅层)。当你继续了解集成 iCloud 到你的应用程序,本章提出了你可能需要的下一步的方向。In this tutorial, you created a sophisticated iOS app that used iCloud to save its documents. Designing an app to support iCloud involves many decisions, though, and this tutorial only scratches the surface. This chapter suggests some directions you might take next as you continue to learn about integrating iCloud into your apps.

 

处理文件版本冲突问题Handling Document Version Conflicts

应用程序存储文件到 iCloud,必须做好准备,处理不同版本之间的应用存储的文件冲突。在两个不同的设备,当发生相同的文件更改时,可能发生冲突。例如,冲突可能发生在当用户编辑两个不同的设备上的同一个文档,设备目前当前开启,飞机模式,因为它们无法将更改传输到 iCloud 服务服务器 。Apps that store documents in iCloud must be prepared to handle conflicts between different versions of that document. Conflicts can occur when changes are made to the same document on two different devices. For example, a conflict can occur when the user edits the same document on two different devices that are currently in Airplane Mode, because they are unable to transmit changes to the iCloud servers.

虽然冲突不会频繁发生,应用需要处理这些未知的冲突。检测一个基于文件的应用,你必须为 UIDocument类的状态更改通知进行注册。如果文件进入 UIDocumentStateInConflict状态,你的应用需要检索文件版本冲突和设备如何更好继续。Although conflicts do not happen too often, apps need to be prepared to handle them. To detect conflicts in a document-based app, you must register for the state change notifications of the UIDocument class. If the document enters the UIDocumentStateInConflict state, your app needs to retrieve the conflicting document versions and decide how best to proceed.

更多关于处理版本冲突的信息,查看 iCloud Design Guide。For more information about handling version conflicts, see iCloud Design Guide.

 

显示上传和下载进度给用户Displaying Upload and Download Progress to the User

当文件变得更大,当传递或接收 iCloud,你可能想到提供一些反馈给用户。NSURL类的实例化保持属性,告诉你基础文件的当前传输状态。你可以用这些值决定是否一个文件要下载到本地设备,还有是否改变已经上传到 iCloud。你也可以用这些值查看当前下载和上传操作的进度。For documents that grow to be large, you might want to provide some feedback to the user when sent to and from iCloud. Instances of the NSURL class maintain attributes that tell you the current transfer status of the underlying file. You can use these values to determine whether a file is downloaded to the local device and whether changes have been uploaded to iCloud. You can also use these values to check the current progress of download and upload operations.

访问 iCloud 状态属性的信息,查看 NSURL Class ReferenceFor information about accessing the iCloud status attributes, see NSURL Class Reference.

 

处理 iCloud 不可用的例子Handling Cases in Which iCloud Is Unavailable

启动后接着就调用 URLForUbiquityContainerIdentifier方法 的一个优势:这个方法可以让你决定是否 iCloud 在应用生命周期的前段时间是可用的。如果方法的返回值为 nil,意味着 iCloud 容器目录不能达到,通常是因为用户的设备没有配置 使用iCloud。(发展期间,无法访问 iCloud,通常意味着在你的应用的 iCloud 权限的配置中有一个错误。)One of the advantages of calling the URLForUbiquityContainerIdentifier: method shortly after launch is that it lets you determine whether iCloud is available early in the life of your app. A return value of nil from the method means that the iCloud container directory could not be reached—usually because the user’s device is not configured to use iCloud. (During development, being unable to access iCloud usually means there is an error in the configuration of your app’s iCloud entitlements.)

你的应用在当iCloud不可用的情况时,应该提供一个流畅的回退位置。例如,你可能存储新的用户文档到本地沙盒,然后在第一次有机会时就将这些文件转移到 iCloud。你应该默默做这些,不要打扰到用户。Your app should provide a smooth fallback position in cases when iCloud is unavailable. For example, you might store new user documents in the local sandbox and transfer them to iCloud at the first opportunity. You should do this quietly and not bother the user.

还需要意识到用户可以在关闭文件和数据选择或者删除当前 iCloud 账号时,关闭应用的 iCloud 访问。虽然这个不应该频繁发生,还是要防御的为你的应用编程,应用在后台暂停或运行时,应用准备好这种改变。具体来说,在移至到后台、返回前台时,调用 URLForUbiquityContainerIdentifier 方法来验证在视图访问任何你应用容器目录的文件时,iCloud 任然是可用的。You should also be aware that the user can turn off your app’s access to iCloud altogether by turning off the Documents & Data option or by deleting the current iCloud account. Although this should not happen often, you should still code your apps defensively and be prepared for this kind of change while your app is suspended or running in the background. Specifically, after having moved to the background and returned to the foreground, call theURLForUbiquityContainerIdentifier: method to verify that iCloud is still available before attempting to access any files or documents in your app’s container directory.

 

提高文档演示界面Improving the Document Presentation Interface

简单文本编辑器的应用查找文件并顺序的呈现到它们被发现的地方。总之,你可能想要证明一个更确定的方式来展现文档到你的应用中。例如,你可以按照字母顺序排序来展现它们,或者维护一个当前排序的记录,也可以将这些信息写入到 iCloud。The Simple Text Editor app searches for documents and presents them in the order in which they are discovered. However, you might want to provide a more deterministic way of presenting documents in your own apps. For example, you could display them in alphabetical order or maintain a record of the current order and write that information to iCloud as well.

 

支持动态命名的文件Supporting the Dynamic Naming of Documents

本指导为新文件名字使用一个静态名字和一个动态数字的组合,但是你自己的应用应该更有创意。这里有一些关于创建好的文件名的建议:The tutorial used a combination of a static name and a dynamic number for new document names, but your own apps should be more creative. Here are some tips for creating good document names:

  • 用一个最初的只是名字,指示你的应用程序创建的内容。不要只是创建“无标题的”文件。将文件名创建的更明确。例如,一个绘画程序可能为基本文档名称使用“你的创建”或者“帆布”。Use an initial name that is indicative of the content your app creates. Do not just create “Untitled” documents. Make the document names more specific. For example, a painting program might use “My Creation” or “Canvas” for the base document name.

  • 为用户提供给一个简单但是不引人注目的方式来改变文档的名称。让用户点击文档名称并在适当的地方编辑它。不要发布警告或者用一个接口把用户拉出当前的上下文。Provide a simple but unobtrusive way for the user to change document names. Let the user tap the document name and edit it in place. Do not post alerts or use an interface that pulls the user out of the current context.

  • 对包含文本内容的文件,坚持使用内容(代替文件名称)来定义文件名。这种方式类似于笔记应用展示信息的方式。因为用户没有直接访问底层文件系统,展现初始文件内容很多情况下比展现文件名称要好。For documents with text content, consider using that content (instead of the filename) to identify the document. This approach is similar to the way the Notes app displays information. Because users do not have direct access to the underlying file system, displaying the initial document content is often better than displaying a file name.

 

支持键-值存储Supporting the Key-Value Store

如果想让你的应用共享偏好设置,并且其他非至关重要的配置数据,通过 iCloud 使用 NSUbiquitousKeyValueStore 类这样做。它在 iCloud 中提供一个简单的接口来设置 键值对数据。If you want your app to share preferences and other noncritical configuration data, use the NSUbiquitousKeyValueStore class to do so using iCloud. This class behaves in a similar way to the NSUserDefaults class. It provides a simple interface for setting key-value pair data in iCloud.

更多关于使用类的信息,查看 Preferences and Settings Programming GuideFor more information about using the NSUbiquitousKeyValueStore class, see Preferences and Settings Programming Guide.

 

使用核心数据与iCloudUsing Core Data with iCloud

核心数据为你的应用数据结构建模提供一系列的复杂精致的工具,并且在你的应用中有效的管理它们。不像 SQLite 数据库,核心数据存储可以通过 iCloud 共享给用户的设备。核心数据通过仅传送变化到 iCloud来管理这个操作,如此以来,它们可以被合并到每个设备的本地数据库。Core Data provides a set of sophisticated tools for modeling your app’s data structures and managing them efficiently in your app. Unlike live SQLite databases, Core Data stores can be shared among a user’s devices through iCloud. Core Data manages this operation by sending only the changes to iCloud, so that they can be incorporated into local databases on each device.

更多关于使用 iCloud 核心数据的信息,查看 “Designing for Core Data in iCloud”For more information about using Core Data with iCloud, see “Designing for Core Data in iCloud”.

 

学习更多关于文件协调Learning More About File Coordinators

在某种程度上,你可能需要理解更多关于文件协调员在 iCloud 中扮演的角色。虽然 UIDocument 类提供文件协调员的更多动作,其中一些动作可能需要你自己来建立一个文件协调员。例如,当在简单文本编辑(Simple Text Editor)中删除文件,你需要建立一个自己的文件协调员,并用这个来执行操作。如此以来,当你可能需要使用它们时,就可以理解文件协调员在你的应用中的角色的重要性。At some point, you might need to understand more about the role file coordinators play in iCloud. Although the UIDocument class provides the file coordinator for many actions, some actions may require you to create a file coordinator yourself. For example, when deleting files in Simple Text Editor, you had to create a file coordinator of your own and use it to perform the operation. Therefore, it is important that you understand the role file coordinators play in your app and when you might need to use them.

更多关于何时使用文件协调员的信息,查看 File System Programming GuideFor more information about when to use file coordinators, see File System Programming Guide.

转载于:https://www.cnblogs.com/zyingn/articles/iOS_translation16.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/292558.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

operation 多线程

2.Cocoa Operation 优点:不需要关心线程管理,数据同步的事情。Cocoa Operation 相关的类是 NSOperation ,NSOperationQueue。NSOperation是个抽象类,使用它必须用它的子类,可以实现它或者使用它定义好的两个子类&#…

Android插件化开发基础之Java动态代理(proxy)机制的简单例子

一、代码 package com.sangfor.tree;import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy;interface ProxyInterFace { public void proxyMethod(); } class TargetObject implements ProxyInterFace { publ…

python获取键盘事件_50-用Python监听鼠标和键盘事件

PyHook是一个基于Python的“钩子”库,主要用于监听当前电脑上鼠标和键盘的事件。这个库依赖于另一个Python库PyWin32,如同名字所显示的,PyWin32只能运行在Windows平台,所以PyHook也只能运行在Windows平台。 关于PyHook的使用&…

解读最新的 Xamarin 更新

微软中国MSDN 点击上方蓝字关注我们Good news——Visual Studio 2022 包括了 Xamarin 对 Android 12和苹果最新的 Xcode 13 版本下的 iOS、iPadOS、macOS 和 tvOS 的支持,以及适用于支持它们的最新 Xamarin.Forms 版本。让我们一起来了解下最新 Xamarin版本&#x…

原来医生的处方不是随便乱写的...

1 奇奇怪怪的知识又增加了(素材来源网络,侵删)▼2 像极了早上刚睡醒炸毛的你▼3 原来医生的处方不是瞎写的▼4 当爷爷不当孙子(素材来源网络,侵删)▼5 40厘米的身高差(素材来源网络&#xf…

Uva 11400,照明系统设计

题目链接:https://uva.onlinejudge.org/external/114/11400.pdf 题意:有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L。注意到,电压相同的灯泡只需…

Android之解决Gigaset手机不能设置DeviceOwner权限提示already provisioned问题

客户那里有Gigaset手机,安装我们的产品需要注入DeviceOwner,但是刚恢复默认出厂的Gigaset手机很奇葩,注入权限的提示下面错误,导致不能使用我们的产品 设置DeviceOwner权限是有限制的,需要手机账号(acount)为0 1 我们用命令查看手机的帐号 adb shell dumpsys account …

Python-理解装饰器

文章先由stackoverflow上面的一个问题引起吧&#xff0c;如果使用如下的代码&#xff1a; makebold makeitalic def say():return "Hello" 打印出如下的输出&#xff1a; <b><i>Hello<i></b> 你会怎么做&#xff1f;最后给出的答案是&#x…

收集网络状态(Ping),并用邮件通知管理员

在没有第三方工具对网络进行监控的话&#xff0c;要检查网络中某台主机&#xff0c;或是某个IP地址通讯是否正常&#xff0c;我们通常用手动PING来进行测试。有了PowerShell&#xff0c;我们可以用他定时Ping网络上的几个IP地址&#xff0c;然后把ping的个延时时间用邮件通知给…

sql 某列数据全部为0则不显示该列_数据产品经理养成记(五):汇总分析

学会了如何查找数据后&#xff0c;接下来就要对数据进行分析处理&#xff0c;比如求和、平均值、加总等等。这些对数据的加工处理通过汇总函数来实现。汇总函数在之前的两篇文章中都有涉及&#xff0c;这里采用概念--案例--总结的方式&#xff0c;集中介绍一下。1.什么是汇总函…

如何通过 反射 调用某个对象的私有方法?

咨询区 Jeromy Irvine我的类中有一组私有方法&#xff0c;我现在想根据灵活的输入值来动态调用其中的私有方法&#xff0c;代码类似是这个样子。MethodInfo dynMethod this.GetType().GetMethod("Draw_" itemType); dynMethod.Invoke(this, new object[] { methodP…

vim学习日志(5):vim下wimrc的配置,解决中文乱码问题

解决linux下vim乱码的情况&#xff1a;(修改vimrc的内容&#xff09; 全局的情况下&#xff1a;即所有用户都能用这个配置 文件地址&#xff1a;/etc/vimrc 在文件中添加&#xff1a; set fileencodingsutf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencodingutf-8 set enco…

Android插件化开发之AMS与应用程序(客户端ActivityThread、Instrumentation、Activity)通信模型分析

转载来自&#xff1a;http://blog.csdn.net/qinjuning/article/details/7262769 今天主要分析下ActivityManagerService(服务端) 与应用程序(客户端)之间的通信模型&#xff0c;在介绍这个通信模型的基础上&#xff0c;再 简单介绍实现这个模型所需要数据类型。 本文所介绍内容…

深入了解JavaScript中的正则表达式构造函数和正则表达式字面量

正则表达式是在处理字符串时非常有用的工具&#xff0c;它可以帮助我们进行模式匹配、搜索和替换操作。在JavaScript中&#xff0c;我们可以使用正则表达式构造函数 RegExp 或正则表达式字面量来创建正则表达式对象。本文将深入探讨这两种方式的不同之处&#xff0c;并通过代码…

iOS开发UI篇—直接使用UITableView Controller

iOS开发UI篇—直接使用UITableView Controller 一、一般过程 1 //2 // YYViewController.h3 // UITableView Controller4 //5 // Created by 孔医己 on 14-6-2.6 // Copyright (c) 2014年 itcast. All rights reserved.7 //8 9 #import <UIKit/UIKit.h> 10 11 inter…

怎么做图片文字二维码一起_怎么做?才能让文字编排更出彩

在之前视觉设计文章中&#xff0c;我把视觉设计大致罗列了四个方向&#xff0c;更多的是希望能够为大家带来一些努力方向&#xff0c;在设计的路上不那么困惑迷茫&#xff0c;视觉设计本身涵盖的范围就比较广&#xff0c;同时也没有什么衡量的标准和具体的特征&#xff0c;只有…

×××

的规则如下&#xff1a;任意的5张牌&#xff0c;只要其中的三张能凑满10的整数倍&#xff0c;就算有牛&#xff0c;否则没牛。在有牛的前提下&#xff0c;另外两张牌相加取个位数上的数字&#xff0c;数字是几就是牛几。且数字越大的一方胜。碰到数字相当的情况下&#xff0c;就…

.NET6之MiniAPI(八):日志

说明&#xff1a;本篇简单说一下日志中常用的几个点&#xff0c;关于日志&#xff0c;后面重点会说到三方日志提供程序在MiniAPI中&#xff0c;可以通过方法或构造函数中&#xff0c;获取框架自动注入的日志类型&#xff0c;如下方式&#xff1a;app.MapGet("/test",…

为什么你闻不到自己胳肢窝的味道?

▲ 点击查看生活中&#xff0c;我们常常会选择性地忽略一些事。吃螺蛳粉的人不会觉得屋子臭&#xff0c;而别人身上有一点烟味就可以闻到。公司的厕所&#xff0c;别人用完后&#xff0c;总觉得比自己用完时更臭。夏天胳肢窝出汗的味道&#xff0c;自己从来都闻不到&#xff0c…