Professional Documents
Culture Documents
Abstract
The purpose of the DotMac Kit and its contained classes is to give developers all of the
tools required to tightly integrate the Internet-based services offered by Apple in its .Mac
product with their own. Additionally, .Mac developers have the opportunity to join
the .Mac Affiliate Program and earn a commission for every new .Mac membership that
they help generate.
The basic usage pattern for the Kit is that a DMMemberAccount instance can be created
and used to perform .Mac-specific functions, such as checking which services are
available to a given account, and can also be used in creating instances of individual
sessions with .Mac services, such as the iDisk service or the store-and-forward messaging
service. Each session is a specific object that encapsulates all state, network, and general
overhead work required to interface efficiently with a given .Mac service.
Version 2.0 of the DotMac Kit introduces API’s for Internet-based collaboration,
workflow and security, enabling powerful networked features not available on any other
platform.
Class Diagram
Description
At the highest level, the DotMac Kit enables you to perform data transfer, distributed
messaging and related user account transactions with the .Mac Internet Services
environment, all without having to worry about the underlying transport protocols,
security, or servers. The framework enables data I/O via iDisk and an interface
into .Mac’s store-and-forward messaging service, along with mechanisms for dealing
with specific attributes of a member’s .Mac account. Used by Apple’s own iApps
and .Mac’s application servers, the Kit is open standards-based and is the easiest way to
integrate with .Mac.
Many applications can benefit from the DotMac Kit. Document-centric applications, for
instance, can use the Kit’s workflow and collaboration features for sharing documents,
and can use iDisk for data backup or secure distribution. Multi-player or turn-based
games can use the Kit to communicate events across computers or to save game state to
an iDisk. Any application that requires reliable notifications or inter-application
communication, be it for distributed solutions or anything involving resource tracking or
reservation, can benefit.
And it’s free. At no cost to your application, the DotMac Kit gives you access to
the .Mac infrastructure and to well over half a million paying members. .Mac’s scalable
services, systems support and 24/7 monitoring make adding Internet-based features to
your application headache-free. Plus, you earn $15 for every member you sign up (see
the included ‘Affiliate Program’ document for more information).
The rest of this document covers the DotMac Kit 2.0 API’s in detail. Read on to learn
how easy it is to include powerful Internet-based features in your app.
2
Table of Contents
Constants ...........................................................................................4
DMMemberAccount .............................................................................................................. 15
DMSecondaryUser .................................................................................................................20
DMGroup ................................................................................................................................ 21
DMUtilities ............................................................................................................................. 25
DMMessageSubscriber ......................................................................................................... 43
DMTopic ................................................................................................................................. 49
DMMessage ........................................................................................................................... 52
3
Constants
The NSString key constants below are used to access quota property values contained in
the NSDictionary created by DMiDiskSession’s -quotaAttributes method (the
NSDictionary is retrieved using DMTransaction’s result method):
Key Constant Corresponding Value Type
kDMiDiskQuotaInBytes NSNumber (bytes)
kDMiDiskSpaceUsedInBytes NSNumber (bytes)
Certain methods in this framework return an “Undefined” value when appropriate and as
noted in the method descriptions of this document.
Status Constant Meaning
kDMUndefined Used by individual methods as noted in this
document’s method descriptions.
5
DMTransaction’s -transactionState method returns one of the following integer status
codes:
Transaction State Constant Meaning
kDMTransactionNotStarted The transaction has not yet started.
kDMTransactionActive The transaction is in progress.
kDMTransactionSuccessful The transaction completed successfully and
without error.
kDMTransactionAborted DMTransaction’s abort method was called,
halting the given transaction.
kDMTransactionHadError A non-success http status code was returned,
a network error occurred, or the expected
data was not received. To get the exact error
that occurred, call DMTransaction’s
httpStatusCode or errorType methods.
Privilege constants used for setting privileges when setting access rights on
securable .Mac entities using DMSecurity methods (privileges are inherited unless
explicitly overridden):
Privilege Constant Meaning
kDMRead Includes ‘read’ and ‘list’ access to a given
entity.
kDMWrite Includes ‘create’, ‘modify’ and ‘delete’
access to a given entity.
kDMModify Includes ‘modify’ access to a given entity.
Does not include ‘create’ or ‘delete’ access.
kDMReadChildren Includes ‘read’ and ‘list’ access to children
of a given entity only. Does not include
‘read’ and ‘list’ access to the entity itself.
6
Principal Type Constants Meaning
kDMMemberAccount Type for principal representing .Mac
member.
kDMSecondaryUser Type for principal representing a .Mac
member-owned secondary user.
kDMGroup Type for principal representing a .Mac
member-owned group.
7
Using Transactions
At the heart of the DotMac Kit is the DMTransaction class, which peforms all network
operations with .Mac. All methods in the Kit that return DMTransaction objects conform
to the DMTransactionGenerator protocol, a protocol that provides control over whether
transactions are done asynchronously or synchronously (the default is always async) and
that provides a mechanism for setting a transaction delegate object that conforms to the
informal DMTransactionDelegate protocol.
DMTransaction
Tracking transactions
- (NSString *)transactionID;
Returns a globally unique identifier string for this transaction.
8
before the context can be set--since callbacks are made on the same client thread which
launched the transaction, setting the context simply needs to be done immediately after
generating the transaction and in the same thread. That way, even if the transaction
completes immediately, the context will still be set before the completion callback is
made.
- (id)context;
Returns the context object set for this transaction. This value is nil by default.
- (NSString *)uri;
Returns the target uri sent in this transaction’s originating request.
- (BOOL)isSuccessful;
Returns YES if the transaction has finished successfully, no network errors occurred, and
a valid http status code was returned. Otherwise, returns NO.
- (BOOL)isFinished;
This method will return YES if the given transaction is no longer active, due to success,
error or cancellation. Otherwise, NO is returned.
- (int)transactionState;
Returns one of the following integer constants:
Transaction State Constant Meaning
kDMTransactionNotStarted The transaction has not yet started.
kDMTransactionActive The transaction is in progress.
kDMTransactionSuccessful The transaction completed successfully and
without error.
kDMTransactionAborted DMTransaction’s abort method was called,
halting the given transaction.
kDMTransactionHadError A non-success http status code was returned,
a network error occurred, or the expected
data was not received. To get the exact error
that occurred, call DMTransaction’s
httpStatusCode or errorType methods.
9
- (int)httpStatusCode;
Returns the HTTP status code for the request if applicable. Check RFC 2616 (HTTP/1.1)
for a complete list of all of the applicable status codes. Some of the most noteworthy
ones are:
200 – Success
304 – Not Modified
401 – Authorization required
403 – Forbidden. Your authorization credentials will not allow the transaction
attempted.
404 – Not Found
[Note: kDMUndefined will be returned if the transaction has not yet completed, if an http
status code is not applicable for the given transaction type, or if the transaction failed
before an HTTP status code could even be received, as might be the case if the client
computer could not contact the .Mac environment for some reason.]
- (int)errorType;
If an error occurred while generating the response associated with this object, this method
will return a specific error type, as defined in the “Constants” section of this document.
If an unknown error occurred, kDMUnknownError is returned. However, if no error
occurred or the response has not yet completed when this method is called,
kDMUndefined will be returned. [Note: If the http status code that was received is
considered a failure code for the given transaction, kDMUnknownError is returned – the
http status code can be retrieved using the httpStatusCode method of this class.]
- (id)result;
Returns the result object of the given transaction as defined by the type of request the
transaction is handling, if currently available and applicable. Otherwise returns nil.
- (SInt64)contentLength;
Returns the length in bytes of the content being downloaded or uploaded. This returned
length does not change over the life of the given transaction, except in the case where this
method is called immediately after a GET request is started, before the content length has
been received from the server—this method returns kDMUndefined if called too early.
- (SInt64)bytesTransferred;
Most useful for asynchronous operations, this method returns the number of bytes
downloaded or uploaded thus far.
10
Cancelling an in-flight transaction
- (void)abort;
Stops the current transaction if it is running asynchronously, halting its progress. If the
transaction is already complete (or resulted in an error) this method has no effect.
11
DMTransactionDelegate (Informal Protocol)
12
DMTransactionGenerator (Formal Protocol)
- (void)setTransactionDelegate: (id)delegate;
This method is used to set the delegate object which will receive status messages from
asynchronous transactions generated by the object that conforms to this protocol. The
object passed in this method's delegate parameter must conform to the informal
DMTransactionDelegate protocol. Transaction delegates receive their messages on the
run loop originally used to create the given DMTransaction. It is safe to call this method
to change the delegate as needed--since an in-flight DMTransaction object uses the
settings that were in place at the time it was created, calling this method will not affect
any transaction already in progress. A transaction delegate object does not receive
callbacks for transactions executed synchronously.
- (id)transactionDelegate;
This method is used to get the currently set delegate object that receives status messages
from asynchronous transactions generated by the object that conforms to this protocol.
- (void)setIsSynchronous: (BOOL)useSynchronous;
This method is used to set the synchronicity state for generated transactions. Passing
YES for useSynchronous will cause the object's transaction methods to block until they
have either completed their transaction or failed with an error. Passing NO will cause the
methods to that return a DMTransaction object to return immediately, using any
previously set delegate object to signal completion or error. It is safe to call this method
to switch between asynchronous and synchronous modes as needed--since an in-flight
DMTransaction object uses the settings that were in place at the time it was created,
calling this method will not affect any transaction already in progress. [Note: The default
mode is asynchronous.]
- (BOOL)isSynchronous;
This method returns the synchronicity state used for newly generated transactions. YES
is returned for synchronous or NO for asynchronous. [Note: The default mode is
asynchronous.]
13
Credentials and Account Management
Objects conforming to the DMCredential protocol, such as DMMemberAccount and
DMSecondaryUser are used to provide credentials for .Mac session classes, such as
DMiDiskSession, DMMessagePublisher and DMMessageSubscriber. Besides providing
credentials, the DMMemberAccount class offers a mechanism for obtaining account
status such as which .Mac services are available and how many days the account has left
before expiration. It also provides methods for creating member-owned secondary users
and groups. (We’ll describe later how .Mac resources can be shared by using the Kit’s
access control features to grant access to other .Mac members, secondary users or
groups.)
14
DMCredential (Formal Protocol)
- (NSString *)name;
A username string is returned.
- (NSString *)password;
A password string is returned.
- (NSString *)owner;
The name of the .Mac member who owns the credential is returned.
DMMemberAccount
(Conforms to DMCredential, DMPrincipal, DMTransactionGenerator)
+ accountFromPreferencesWithApplicationID:
(NSString *)creatorCode;
Returns an initialized, auto-released instance of DMMemberAccount keyed to a specific
application’s identification string. The instance returned will have the .Mac name and
password from the system pre-applied. Pass the unique 4-character application identifier
obtained from http://developer.apple.com/datatype/creatorcode.html.
- (NSString *)applicationID;
The application ID currently set for this DMMemberAccount object is returned.
- (NSString *)applicationName;
The human-readable name of the calling application is returned if set.
- (int)validateCredentials;
Use this method to check that the given account contains valid .Mac credentials. The
returned integer will correspond to one of the “Status Constants” defined in the Constants
section of this document.
- (BOOL)matchesSystemCredentials;
Returns true if the name and password currently set for this DMMemberAccount object
match the .Mac credentials stored on the system.
- (DMTransaction *)servicesAvailableForAccount;
The returned DMTransaction object’s result method returns an NSArray of NSString
entries corresponding to available services for the .Mac account represented by this
DMMemberAccount instance. If a given .Mac service is enabled for this account, then
the array will contain a string equal to one of these NSString constants:
Service Constant Meaning
kDMiDiskService The account has iDisk storage associated
with it.
kDMEmailService The account has an email address along with
the associated email storage.
16
kDMWebHostingService The account has web hosting capabilities
through its iDisk’s Sites folder.
kDMiSyncService The account has access to .Mac’s iSync-
related functionality.
[Note: If the account credentials do not exist or some other error occurs, the returned
DMTransaction’s errorType method can be used to identify the error.]
- (DMTransaction *)daysLeftUntilExpiration;
The returned DMTransaction object’s result method returns an NSNumber representing
the number of full days left until the given account expires.
[Note: If the account credentials do not exist or some other error occurs, the returned
DMTransaction’s errorType method can be used to identify the error.]
- (DMTransaction *)canUpgradeAccount;
The returned DMTransaction object’s result method returns an NSNumber, whose
Boolean value can be retrieved using NSNumber’s boolValue method. This value will be
YES if the DMMemberAccount object’s credentials are associated with an existing
account that can be upgraded, such as a trial or email-only account, or if the account has
expired and needs to be renewed. Otherwise, the resulting value will be NO.
[Note: If the account credentials do not exist or some other error occurs, the returned
DMTransaction’s errorType method can be used to identify the error.]
- (void)upgradeAccount;
This method will launch the user’s default web browser and open the appropriate .Mac
membership upgrade page, which is localized based on system preferences.
- (NSURL *)accountUpgradeURL;
This method provides access to the same localized URL that the upgradeAccount method
loads in the default browser.
+ (void)signUpNewMember;
This method will launch the user’s default web browser and open the .Mac new member
sign-up page, which is localized based on system preferences. This method can be used
when the user of the given application is not yet a .Mac member and cannot fully enjoy
the application’s features without a .Mac account.
17
+ (void)signUpNewMemberWithApplicationID: (NSString *)appID;
This method performs the same function as the +signUpNewMember method, and
additionally ensures that the owner of the provided application ID (if a member of
the .Mac Affiliate Program) earns a commission whenever a user of their application
becomes a paying .Mac member. For more information on the .Mac Affiliate Program,
please visit http://www.mac.com/1/affiliates/faq.html.
+ (NSURL *)signUpURL;
This method provides access to the same localized URL that the signUpNewMember
method loads in the default browser. [Note: The URL returned by this method should not
be hard-coded within an application, as it may change in the future.]
- (DMTransaction *)secondaryUserNames;
Lists all secondary users owned by this .Mac member. Returns a DMTransaction object
whose -isSuccessful method can be used to test for success and whose -result method
returns an NSArray of NSStrings on success.
- (DMTransaction *)groupNames;
Lists all groups owned by this .Mac member. Returns a DMTransaction object whose
-isSuccessful method can be used to test for success and whose -result method returns an
NSArray of NSString group names upon success.
19
DMSecondaryUser
(Conforms to DMCredential, DMPrincipal, DMTransactionGenerator)
20
DMGroup
(Conforms to DMPrincipal, DMTransactionGenerator)
Convenience API
- (NSString *)name;
Returns the name of the .Mac member-owned group represented by this DMGroup
object.
- (NSString *)owner;
Returns the name of the .Mac member who owns this group.
- (DMTransaction *)members;
Lists all members of the given .Mac member-owned group. Returns a DMTransaction
object whose -isSuccessful method can be used to test for success and whose -result
method, upon success, returns an NSArray of principal ID strings that identify principals
corresponding to DMMemberAccounts, DMSecondaryUsers and/or other DMGroup
objects.
21
DMPrincipal (Formal Protocol)
The DMPrincipal protocol is implemented by DMMemberAccount, DMSecondaryUser
and DMGroup. [Note: When calling +principalIDWithName:andOwner: for a
DMMemberAccount, the name and owner strings are the same.]
- (NSString *)principalID;
This method is implemented by DMMemberAccount, DMSecondaryUser or DMGroup
and returns the appropriate principal ID string.
22
Security and Access Control
The DMSecurity protocol is implemented by DMiDiskSession, DMMessagePublisher
and DMMessageSubscriber and allows the owner of a .Mac resource to apply ACLs to
that resource. (Examples of how to use the DMSecurity methods for each of these
three .Mac session classes can be found within each of their respective API sections in
this document.) This section describes the DMSecurity protocol in detail, along with the
DMUtilities class, which provides assistance in parsing principal ID strings returned by
DMSecurity methods.
The DMSecurity protocol is used to get and set access privileges for securable entities
(such as DMTopics and NSStrings paths representing iDisk resources). Access is granted
to principals corresponding to DMMemberAccounts, DMSecondaryUsers and
DMGroups. [Principals are represented by principal ID’s, which can be obtained by
calling the +principalIDWithName:andOwner method on a DMMemberAccount,
DMSecondaryUser or DMGroup object. If you already have an instance of one of these
objects you can call its –principalID instance method instead.]
23
section of this document and include kDMRead, kDMWrite, kDMModify and
kDMReadChildren.)
If the access privileges array is nil, this method will remove all access for the given
principals. The entity argument is either a DMTopic object or an NSString path
representing an iDisk resource. The principals argument is an NSArray of principal ID
strings that identify the unique principals corresponding to DMMemberAccounts,
DMSecondaryUsers and/or DMGroups. Returns a DMTransaction object whose -
isSuccessful method can be used to test for success.
24
DMUtilities
- (NSDictionary *)principalPropertiesFromPrincipalID:
(NSString *)principalID;
This utility method is used to parse a principal ID string returned by a DMPrincipal
method. This method returns a dictionary with values for the following keys:
kDMPrincipalName, kDMPrincipalOwner and kDMPrincipalType. The
kDMPrincipalOwner key corresponds to the name of the .Mac member who owns the
given principal (this is the same as the principal name if the principal represents a
DMMemberAccount) and the kDMPrincipalType key corresponds to one of the
following: kDMMemberAccount, kDMSecondaryUser or kDMGroup. (These constants
are defined in the “Constants” section of this document.)
25
Transferring Data with iDisk
At the core of the DotMac Kit is an implementation of an open standards-based
WebDAV client (RFC #2518). This allows DMiDiskSession objects to directly interact
with the .Mac iDisk service, which is also based on WebDAV.
Built on top of the DMiDiskSession class, which includes everything a user of this
framework needs to manipulate data on an iDisk, is a convenience category called
DMiDiskFileManager, which has an API and functionality representing a subset of that of
NSFileManager. DMiDiskFileManager is a wrapper around DMiDiskSession’s
WebDAV-based calls, and facilitates synchronous iDisk access through an API which will
be familiar to many developers. However, direct use of DMiDiskSession is the
recommended mode of communication with the iDisk, since it is more efficient, allows
asynchronous calls, and will be the class which gets updated in future framework releases
as enhanced WebDAV-based functionality is added. [Note: DMiDiskSession objects are
in asynchronous mode by default.]
26
DMiDiskSession
(Conforms to DMSecurity, DMTransactionGenerator)
27
+ iDiskSessionWithCredentials: (id <DMCredential>)credentials
andOwner: (NSString *)memberName;
This method returns an auto-released iDisk session instance that can be used to perform
I/O transactions with the .Mac iDisk servers. It takes an object that conforms to the
DMCredential protocol and also takes the name of the .Mac member whose iDisk is to be
accessed using the provided credentials.
Convenience API
- (id <DMCredential>)credentials;
Returns the DMCredential-conforming object containing the credentials used to access
this session’s iDisk.
- (NSString *)owner;
Returns the name of the .Mac member who owns the iDisk being accessed by this
session.
- (DMTransaction *)quotaAttributes;
Use this method to get the user’s iDisk quota value along with the amount of storage
space that is currently used. The returned DMTransaction object’s result method returns
an NSDictionary containing two NSNumber values, which can be retrieved using the
following key constants:
Key Constant Corresponding Value Type
kDMiDiskQuotaInBytes NSNumber (bytes)
kDMiDiskSpaceUsedInBytes NSNumber (bytes)
28
Downloading data
29
Uploading data
- (DMTransaction *)putLocalFileAtPath: (NSString *)localPath
toPath: (NSString *)destinationPath;
This method places the contents of a local file into a new server-side file at the given
destination path. If the localPath parameter refers to a symlink, the symlink will not be
preserved—rather, the resource it references will be uploaded. [Note: Call will fail if all
sublevels of destinationPath (excluding the object itself) do not already exist, and the call
may return nil if an invalid localPath argument is passed.]
Returns a DMTransaction object that can be used to get the result of the transaction,
status, payload, and many other pieces of information about the actual
transaction.
30
Moving and Copying resources
Deleting resources
Locking resources
31
DMTransaction object’s result method will return an NSArray of NSString’s representing
the exact uri’s which are currently locked. To maintain a lock, issue a relock request on
the same resource before the original lock has expired. [Note: The lock created is a
cooperative, ‘write’ lock.]
Returns a DMTransaction object that can be used to get the result of the transaction,
status, payload, and many other pieces of information about the actual transaction.
32
an NSDictionary containing an NSNumber value (accessible using the kDMLockTimeout
key) which is the lock timeout that was granted by the server. Once refreshed, the lock
will expire after the time specified by the granted lock timeout (in seconds) has passed.
Attempting to relock a resource that is not locked will always fail. If the relock request
fails because the specified resource or its parent was originally locked by another client,
the returned DMTransaction object’s result method will return an NSArray of NSString’s
representing the exact uri’s which are currently locked. [Note: The lock created is a
cooperative, ‘write’ lock.]
Returns a DMTransaction object that can be used to get the result of the transaction,
status, payload, and many other pieces of information about the actual transaction.
- (void)setDefaultLockDuration: (NSTimeInterval)lockDuration;
This method sets the default lock duration, in seconds, used by all lock-related
DMiDiskSession methods that do not specify a transaction-specific lock duration of their
own. If this method is not called, the default lock duration is 5 minutes, given in seconds.
- (NSTimeInterval)defaultLockDuration;
Returns the default lock duration set for this DMiDiskSession instance. If no default lock
duration has been set for this instance using the setDefaultLockDuration: method, an
NSTimeInterval representing 5 minutes, given in seconds, is returned.
34
DMiDiskFileManager (Category of DMiDiskSession)
- (BOOL)createDirectoryAtPath:(NSString *)path
attributes:(NSDictionary *);
This method will create a new directory at the given remote path. It has the same usage
as the corresponding method of NSFileManager. However, it does not support the setting
of attributes and if a non-nil attributes argument is passed to this method, it will be
ignored.
- (BOOL)createFileAtPath:(NSString *)path
contents:(NSData *)contents
attributes:(NSDictionary *)attributes;
This method creates a remote file at path that contains contents, behavior which matches
the style of the corresponding method of NSFileManager. However, it does not support
the setting of attributes and if a non-nil attributes argument is passed to this method, it
will be ignored.
- (BOOL)copyPath:(NSString *)source
toPath:(NSString *)destination
handler:(id)handler;
This method will create a copy of the source resource at the given destination path, but
will not overwrite an existing resource. Each path argument can be either a local or a
remote path—passing a local source path and remote destination path leads to an upload
of a local resource, while passing a remote source path and local destination path leads to
a download of a remote resource. If two remote paths are provided as arguments, this
method issues a single, server-side COPY request. This method has usage similar to that
of the corresponding method of NSFileManager. However, it does not support the usage
of a callback handler and if a non-nil handler argument is passed to this method, it will be
ignored. In the case of an upload or download, only the data forks of files and directories
are copied. In the case of an upload, local symlinks are not preserved—when a symlink
is encountered, the resource it references will be uploaded. [Note: If two local paths are
provided as arguments, this method calls NSFileManager’s copyPath:toPath:handler:
method with whatever handler argument was provided.]
35
- (BOOL)movePath:(NSString *)source
toPath:(NSString *)destination
handler:(id)handler;
This method will move the source resource to the given destination path, but will not
overwrite an existing resource. Each path argument can be either a local or a remote
path—passing a local source path and remote destination path leads to an upload of a
local resource, while passing a remote source path and local destination path leads to a
download of a remote resource. If two remote paths are provided as arguments, this
method issues a single, server-side MOVE request. This method has usage similar to that
of the corresponding method of NSFileManager. However, it does not support the usage
of a callback handler and if a non-nil handler argument is passed to this method, it will be
ignored. In the case of an upload or download, only the data forks of files and directories
are moved. In the case of an upload, local symlinks are not preserved—when a symlink
is encountered, the resource it references will be uploaded. [Note: If two local paths are
provided as arguments, this method calls NSFileManager’s movePath:toPath:handler:
method with whatever handler argument was provided.]
- (BOOL)removeFileAtPath:(NSString *)path handler:(id)handler;
This method will remove the resource at the given remote path and has the same usage as
the corresponding method of NSFileManager. However, it does not support the usage of
a callback handler and if a non-nil handler argument is passed to this method, it will be
ignored.
- (BOOL)fileExistsAtPath:(NSString *)path;
Returns YES if the remote file specified in path exists, or NO if it does not.
3) Grant read access to a shared folder such that any resource it contains can be
accessed, but the contents of the folder cannot be listed:
37
Using Store-and-forward Messaging
38
DMMessagePublisher
(Conforms to DMSecurity, DMTransactionGenerator)
+ messagePublisherWithCredentials:(DMMemberAccount *)credentials;
Returns a new, autoreleased DMMessagePublisher session that will use the provided
object’s credentials when publishing DMMessages or otherwise accessing or modifying
DMTopics. The publishing member can publish messages to topics that it itself owns or
to topics owned by other .Mac members.
- initMessagePublisherWithCredentials:
(DMMemberAccount *)credentials;
Returns a newly initialized DMMessagePublisher session that will use the provided
object’s credentials when publishing DMMessages or otherwise accessing or modifying
DMTopics. The publishing member can publish messages to topics that it itself owns or
to topics owned by other .Mac members.
Convenience API
- (DMMemberAccount *)credentials;
Returns the .Mac member object containing the credentials set for this
DMMessagePublisher session. These credentials are used to determine which topics can
have messages published to them or be otherwise modified using this session.
40
- (DMTransaction *)topics;
Lists the topics that this DMMessagePublisher can publish messages to or remove
messages from. Each topic listed may be owned by this session's .Mac member
credentials or by another .Mac member. Returns a DMTransaction object whose
-isSuccessful method can be used to test for success and whose -result method, upon
success, returns an NSArray of all accessible DMTopic objects.
- (NSTimeInterval)defaultTimeToLive;
Returns the default time-to-live that will be used by all DMMessages published by this
session. The default time-to-live value is 7 days. Returns an NSTimeInterval (precision
in seconds).
- (int)setDefaultTimeToLive: (NSTimeInterval)defaultTTL;
Sets the default time-to-live that will be used by all DMMessages published by this
session. The default time-to-live value cannot exceed 30 days. Takes an NSTimeInterval
(precision in seconds). If the provided ttl value not in the valid range,
kDMInvalidParameter will be returned; otherwise, this method returns kDMSuccess.
41
Using DMSecurity on DMMessagePublisher:
//Note: For a DMMemberAccount, the name and owner are the same.
NSString *principalID = [DMMemberAccount principalIDWithName:@”george”
andOwner:@”george”];
DMTransaction *trans = [myMessagePublisher setAccess:accessRights
toEntity:myTopic
forPrincipals:[NSArray arrayWithObject:principalID]];
When a .Mac member is granted access to a topic, an invitation to that member is
automatically generated, which can be retrieved using DMMessageSubscriber’s
invitation-related methods. [Note: If only ‘read’ access is granted on a DMTopic, it
means that the invitee will not be able to publish messages to the topic, only receive
them.]
42
DMMessageSubscriber
(Conforms to DMSecurity, DMTransactionGenerator)
+ messageSubscriberWithCredentials:
(DMMemberAccount *)credentials;
Returns a new, autoreleased DMMessageSubscriber session that will use the provided
object’s credentials when subscribing to DMTopics or accessing a DMTopic’s messages.
The provided .Mac member credentials can be used to subscribe to accessible topics
owned by any .Mac member.
- initMessageSubscriberWithCredentials:
(DMMemberAccount *)credentials;
Returns a newly initialized DMMessageSubscriber session that will use the provided
object’s credentials when subscribing to DMTopics or accessing a DMTopic’s messages.
The provided .Mac member credentials can be used to subscribe to accessible topics
owned by any .Mac member.
Convenience API
- (DMMemberAccount *)credentials;
Returns the .Mac member object containing the credentials set for this
DMMessagePublisher session. These credentials are used to determine which topics can
be subscribed to using this session.
43
represents a topic not owned by this DMMessageSubscriber's credentials, use either the
-topicNamed:andOwnedBy: method or the
-topicNamed:andOwnedBy:withApplicationID: method, as described below.
44
- (DMTransaction *)unsubscribeFromTopic: (DMTopic *)topic;
Removes an existing subscription to the given topic. Removes a subscription specific to
the .Mac member for this session, the machine and local OS X user that the calling
application is running under and the calling application itself. Calling this method deletes
the entry for the given subscription from the local user preferences. As an argument, this
method takes a DMTopic object to which this session's .Mac member credentials have
access. Returns a DMTransaction object whose -isSuccessful method can be used to test
for success.
- (NSArray *)subscribedTopics;
Lists the topics to which this session's .Mac member has subscribed (where the
subscription was originally started on this machine for the current OS X user and
the .Mac member credentials set for this session). Each topic listed may be owned by
any .Mac member. Returns an NSArray of all DMTopic objects for which subscriptions
exist.
- (void)setSubscriptionDelegate: (id)delegate;
Sets the delegate object for this session that will receive callbacks regarding topics of
interest. The callbacks relate either to changes to subscribed topics or to new topic
invitations sent by other .Mac members. The object passed in this method's delegate
parameter must conform to the informal DMSubscriptionDelegate protocol. Delegates
receive their messages on the same run loop originally used in calling this –
setSubscriptionDelegate: method.
- (id)subscriptionDelegate;
Retrieves the delegate object for this session that is set to receive callbacks regarding
topics of interest. The callbacks relate either to changes to subscribed topics or to new
topic invitations sent by other .Mac members. Returns a delegate object conforming to
the informal DMSubscriptionDelegate protocol if a subscription delegate has been set for
this session.
45
Launching apps when a topic changes
46
- (void)removeLaunchableToolForTopics: (NSArray *)topics
withPath: (NSString *)fullPath;
Removes the launchable tool for the specified topic(s). The topics argument is an
NSArray of DMTopic objects for which the given tool should no longer be launched.
The path argument is a fully-qualified path to the tool that was previously added for the
given topics.
- (DMTransaction *)invitationsForTopics;
Lists all unsubscribed DMTopics owned by other .Mac members to which the .Mac
member for this session has been invited to subscribe. Returns a DMTransaction object
whose -isSuccessful method can be used to test for success and whose -result method,
upon success, returns an NSArray of DMTopic objects. To be notified upon receipt of
new invitations immediately, register a subscription delegate that implements the -
invitationsReceivedForTopics: method.
[Note: An invitation for a topic is automatically sent to a .Mac member when that
member is granted access to the topic using the DMSecurity protocol methods
implemented by the DMMessagePublisher session.]
Find out what privileges a .Mac member has for a given DMTopic:
NSArray *accessRights;
//Note: For a DMMemberAccount, the name and owner are the same.
47
DMSubscriptionDelegate (Informal Protocol)
48
DMTopic
(Conforms to DMTransactionGenerator)
A DMTopic object can be passed to DMSecurity protocol methods that take an 'entity'
argument, in order to set access privileges on the given topic. When a .Mac member is
granted access to a DMTopic, an invitation is automatically generated and can be
accessed using a DMMessageSubscriber session.
Convenience API
- (NSString *)name;
Returns the name of the topic.
- (NSString *)owner;
Returns the name of the .Mac member who owns and hosts the topic.
- (NSString *)applicationID;
Returns the creator code of the application that created the topic.
- (DMMemberAccount *)credentials;
Returns the .Mac member object containing the credentials that will be used to access or
modify this DMTopic object. The returned credentials are the same credentials held by
the DMMessagePublisher or DMMessageSubscriber instance that was used to get a
reference to this DMTopic.
- (DMTransaction *)exists;
The returned DMTransaction object’s result method returns an NSNumber, whose
Boolean value can be retrieved using NSNumber’s boolValue method. This value will be
YES if the DMTopic exists and NO otherwise.
[Note: If an error is encountered that prevents the existence check, the returned
DMTransaction’s -errorType method can be used to identify the error.]
49
Retrieving messages from a topic
- (NSArray *)newMessages;
Returns all DMMessages in this DMTopic that have not yet been accessed by the caller.
(The caller is defined as a combination of the .Mac credentials set for the session that
created this DMTopic, the machine and local OS X user that the calling application is
running under and the calling application itself.) This method will most often be called
after a DMMessageSubscriber session’s subscription delegate is informed of a change in
this DMTopic. Returns an NSArray of DMMessages ordered by publication time,
starting with the earliest.
- (NSArray *)messages;
Returns all DMMessages found in this DMTopic on .Mac, as an NSArray of
DMMessages. Messages are ordered by publication time, starting with the earliest.
- (DMMessage *)newestMessage;
Returns the most recent DMMessage in the topic, based on publication time.
- (DMMessage *)oldestMessage;
Returns the oldest DMMessage in the topic, based on publication time.
- (DMTransaction *)removeMessages;
Removes all DMMessages from this DMTopic on .Mac. Returns a DMTransaction
object whose -isSuccessful method can be used to test for success. This method can only
be called if the .Mac credentials being used have ‘write’ access to the given topic.
50
Resetting the time-to-live of a published message
- (void)setIsAutoArrivalEnabledForMessagePayloads:
(BOOL)isEnabled;
This method sets whether future messages received for the topic should have their
payloads downloaded automatically to the local message cache before any callbacks are
made on a DMMessageSubscriber’s subscription delegate. When automatic downloading
(or auto-arrival) of payloads is enabled, which is the default, a call to a DMMessage’s
-payload method simply returns the already-downloaded payload. When auto-arrival is
not enabled for a given topic, a DMMessage’s -payload method will do the extra work of
downloading the payload on request.
This method can be called regardless of whether a subscription to the given topic already
exists. (A message’s meta data—everything but the payload—always arrives
automatically). [Note: Any auto-arrival default set by this method for a topic is
automatically cleared from the local preferences cache if an ‘unsubscribe’ call on the
given topic is ever made in the future.] If this method is being called around the same
time that a subscription to the given topic is being created, it is recommended that this
method be called first, before the call to DMMessageSubscriber’s -subscribeToTopic:
method. This ensures that the desired auto-arrival behavior is in place for the given topic
before any topic-related callbacks are made into a DMMessageSubscriber’s subscription
delegate.
- (BOOL)isAutoArrivalEnabledForMessagePayloads;
This method returns a BOOL value indicating whether future messages received for the
topic should have their payloads downloaded automatically to the local message cache
before any callbacks are made on a DMMessageSubscriber’s subscription delegate.
When automatic downloading (or auto-arrival) of payloads is enabled, which is the
default, a call to a DMMessage’s -payload method simply returns the
already-downloaded payload. When auto-arrival is not enabled for a given topic, a
DMMessage’s -payload method will do the extra work of downloading the payload on
request.
51
DMMessage
(Conforms to DMTransactionGenerator)
Convenience API
- (NSString *)messageID;
Returns this DMMessage's globally unique identifier string.
- (NSString *)publisher;
Returns the name of the .Mac member who published this DMMessage to .Mac. Returns
nil if this DMMessage has not yet been published.
- (DMTopic *)topic;
Returns the topic that contains this DMMessage. Returns nil if this DMMessage has not
yet been published to a topic.
- (NSString *)messageString;
Returns the optional message string set for the DMMessage.
- (DMTransaction *)payload;
Retrieves the optional payload object set for the DMMessage. Upon success, the
returned DMTransaction object’s -result method will return this message’s payload
object, an object that conforms to the NSCoding protocol. If auto-arrival of payloads is
enabled for this message’s parent topic, then the payload object is already available
locally by the time this new message is received and the caller can call the returned
DMTransaction’s -result method right away. However, if auto-arrival is disabled, this
DMMessage’s payload is not downloaded until this -payload method is called. If this
DMMessage’s transaction processing is set to asynchronous, then the status of the
download can be observed by setting this DMMessage’s transaction delegate or through
polling the returned DMTransaction object. [Note: If this DMMessage’s transaction
delegate is not set, then it will inherit any transaction delegate that is explicitly set for its
parent DMTopic or that has been inherited by its parent DMTopic from the session object
used to create it.] If auto-arrival is disabled and this DMMessage’s transaction
53
processing is set to synchronous, then this method will not return until the payload is
completely downloaded. In all cases, the payload is retrieved with a call to the returned
DMTransaction object’s -result method.
- (NSString *)payloadType;
Returns the type corresponding to the payload for this DMMessage. The payload type is
an NSString that represents the file type that would be used if the payload object were
serialized to disk. Returns a type string, or nil if no payload object is set for this
DMMessage.
- (NSDictionary *)properties;
Returns the optional user-defined properties dictionary set for this DMMessage.
- (NSDate *)publicationDate;
Returns the time when this DMMessage was published to .Mac, which is an NSDate
object with precision in seconds. If this DMMessage has not yet been published, this
method returns nil.
- (NSDate *)expirationDate;
If this DMMessage has already been published, this method returns an NSDate that
marks the time this DMMessage expires (with precision in seconds). Otherwise, this
method returns nil. If the expiration time returned for this DMMessage is in the past, it
means that this message is awaiting clean-up.
54
- (NSTimeInterval)timeToLive;
Returns an NSTimeInterval (with precision in seconds) representing the default time-to-
live of 7 days if the default was not overridden by a DMMessagePublisher setting or by a
call to this DMMessage’s -setTimeToLive: method.
- (int)setTimeToLive: (NSTimeInterval)timeToLive;
This method can be used to set the time-to-live for this DMMessage prior to publication.
The default time-to-live is 7 days, and the time-to-live cannot be made longer than 30
days. Takes an NSTimeInterval (precision in seconds). [Note: Calling this method on an
already-published message will result in kDMResourceExists being returned; otherwise,
this method returns kDMSuccess. The -isPublished method can be used to determine
whether this DMMessage has already been published.]
- (BOOL)isPublished;
Tells whether the DMMessage has already been published to .Mac. A DMMessage can
be published to .Mac only once and it becomes immutable once published. An attempt to
publish a DMMessage more than once will fail. Returns a BOOL value.
© 2005 Apple Computer, Inc. All rights reserved. .Mac, Apple, the Apple logo, Mac, Mac OS,
and Macintosh are trademarks of Apple Computer, Inc., registered in the U.S. and other
countries.
55