|
Sync Services provides a powerful and extensible mechanism that enables data to move seamlessly between multiple Macs, devices such as mobiles phones and PDAs, and network services. This ability has long been a part of Mac OS X , through iSync and .Mac, which could manage contacts, calendar items, and bookmarks. Now in Mac OS X v10.4 Tiger, any Mac OS X application can tap into this functionality to sync any kind of data reliably, frequently, and easily. Tiger itself takes advantage of the Sync Services framework to synchronize Keychain items and Mail account settings between multiple Macs. The end result is that the data follows the user around and is always where they want it to be. There are several ways in which you can develop with the Sync Services framework:
This article provides an overview of how Sync Services works and illustrates its multiple modes of operation. First, let's take a look at the architecture of the Sync Services framework. Sync Services Architecture
Sync Services is a based on a client-server model. The server, in this case, is the sync engine and the clients are the applications that utilize the capabilities of the framework. Each sync client is responsible for interpreting sync engine record formats into whatever form is needed by the application or device that client acts for. As well, each client can filter the data as needed to ensure that only the data that is applicable for an application or device is synchronized. The sync engine is flexible enough to support a diverse set of clients. The sync engine performs the work of taking and merging changes from clients, and then computing changes to be communicated to all of the clients; and it can do so as frequently as is needed. The sync engine is also capable of supporting the requests of multiple clients at the same time; however, apps can synchronize independently of each other, allowing fast devices to sync frequently without being bogged down by slow devices.
To ensure that all clients have the correct data, the sync engine maintains a truth database. This database contains the master copy of all of the information for the clients that use the Sync Services framework. When a client performs a sync with the sync engine, its data is synched with that of the truth database, not the data of any other client. This allows each client to maintain its own filtered view of the data without limiting the data that other clients use. The use of a master truth database also allows the sync engine to handle conflicts and duplicates as well as give clients only the changes that they need. The sync engine is able to resolve most complex record changes and duplicates without requiring user input. It can handle changes to individual fields in each record according to its schema and not just to records as a whole. This means that if two clients modify different fields in a record, the engine can merge changes successfully without user intervention. Only in the case of a conflict at the field level will the sync engine require user intervention. Sync Services SchemasThe data handled by the Sync Services framework must be described by a sync schema that details the specifics about the data handled by the sync engine. These models are entity-relationship models and follow the same concepts used by the Core Data framework. These concepts are:
Sync schemas are defined in the property list format and are bundled in a
Each type of data to be handled by Sync Services is represented by a separate sync bundle. For example, the three Sync schemas that ship with Tiger and define bookmarks, calendars, and contacts, are located in the You can take three approaches when working with Sync Services. The first is to simply use an existing schema. This approach works well when you are enabling a new device to work with Mac OS X or want to take advantage of existing types in your application. The second is to extend an existing schema with new types. For example, you might want to add fields to the system contacts schema so that your application can sync special attributes with multiple Macs. The third is to create an entirely new schema for new types. Five Phases of SyncIn the simplest form of syncing, the client pushes state to the sync engine, the sync engine detects and applies those changes to the truth database, and then the client pulls changes back. To accomplish this, every sync operation goes through five phases. At each of these five phases a client can finish or cancel. These phases are:
A sync operation takes place within the scope of an
Sync ModesThe mode in which a sync occurs is a negotiation between client and the sync engine. This is because the process can involve multiple clients, and the final results of the sync depend on the state of all processes involved in the sync. A client is not necessarily given the sync mode it requests. Instead, the sync engine may force another mode depending on the needs of other clients in the sync. The first time a client syncs, it performs a slow sync that pushes all of its records into the sync engine and pulls all of the changes. During the course of a slow sync, the sync engine keeps track of the client's state using a snapshot so that subsequent syncs can be more efficient. This allows the next sync that a client performs to be a fast sync. It should be transparent to the user whether a sync is being performed in fast or slow mode. However, to ensure maximum performance and responsiveness, and that a user's data is up-to-date across applications and devices, most clients should fast sync often and as a result of user changes. ConclusionAs you can see, Sync Services allows you to provide solutions that make sure a user's data is always available to them, no matter where that user is or what device they may be using. It provides the hard logic of handling sync operations as well as conflict resolution and lets you just concentrate on the data to be synced. Using the Sync Services API requires care to perform the right actions at the right time so that user data is seamlessly synchronized, but the reward is that your user's computing experience is decoupled from any one machine or device. How You Can Get StartedGetting started couldn't be easier. The first thing you should do, if you haven't already, is to become an Apple Developer Connection member. A free ADC Online membership provides access to updates to Xcode and other developer tools. The paid ADC Select and ADC Premier memberships go further by providing access to pre-release seeds of system software and development tools, CD and DVD-based monthly mailings of sample code and resources, technical support, and great discounts on new hardware. Next, you'll want to set yourself up with Apple's developer tools suite and IDE, Xcode 2.0. Xcode ships as part of each and every copy of Mac OS X Tiger on the Install DVD. Just double-click on the Xcode 2.0 package on the DVD and the developer tools—as well as a set of example code projects and comprehensive documentation in the ADC Reference Library—will be installed on your system. The documentation and sample code will help you learn more about the technologies covered in this article. For More InformationPosted: 2005-06-06 |