ILSwapService Class Reference
[SwapKit Classes and Protocols]

ILSwapService is a singleton class whose instance (referred to as simply the 'swap service') manages interactions between applications, including the registration of metadata in the shared application catalog and sending and receiving requests based on that metadata. More...

#import <ILSwapService.h>

List of all members.

Public Member Functions

(void) - registerWithAttributes:update:
 Registers this app with the swap service.
(BOOL) - performActionsForURL:
 Called to perform appropriate delegate method calls based on the given URL.
(NSDictionary *) - registrationForApplicationWithIdentifier:
 Returns the registration info for the given application identifier, or nil if it's unavailable.
(BOOL) - sendItem:forAction:toApplicationWithIdentifier:
 Sends one item to the application with the given identifier.
(BOOL) - sendItems:forAction:toApplicationWithIdentifier:
 Sends the given items to the application with the given identifier.
(NSDictionary *) - applicationRegistrationForSendingItems:forAction:
 Searches for a registered application that can receive the given items and perform the given action.
(BOOL) - canSendItems:forAction:
 Returns YES if there is at least one app, other than the current one, that can receive the given items and action, NO otherwise.
(NSArray *) - allApplicationRegistrationsForSendingItems:forAction:
 Searches for a set of registered applications that can receive the given items and perform the given action.
(BOOL) - sendRequestWithAttributes:toApplicationWithRegistration:
 This is the primitive request-sending method.

Static Public Member Functions

(ILSwapService *) + sharedService
 Returns the shared instance of this class.
(BOOL) + didFinishLaunchingWithOptions:
 Convenience method for performing startup actions.
(BOOL) + handleOpenURL:
 Convenience method that calls performActionsForURL: on the swap service instance.

Properties

id< ILSwapServiceDelegatedelegate
 Sets or retrieves the delegate. The object set through this property receives callbacks when SwapKit finds that certain events have happened (for example, that an array of items was received).
NSDictionary * applicationRegistrations
 Returns all application registrations.
BOOL sendingAsynchronously
 This property is YES if the last call to sendItem:forAction:toApplicationWithIdentifier: or sendItems:forAction:toApplicationWithIdentifier: is sending your request asynchronously, NO otherwise.
NSDictionary * applicationRegistration
 This is our application regiatration, that is, the dictionary that was passed to the last registerWithAttributes:update: call since the app started.

Detailed Description

ILSwapService is a singleton class whose instance (referred to as simply the 'swap service') manages interactions between applications, including the registration of metadata in the shared application catalog and sending and receiving requests based on that metadata.

TODO: More detailed information.

Definition at line 143 of file ILSwapService.h.


Member Function Documentation

- (NSArray *) allApplicationRegistrationsForSendingItems: (NSArray*)  items
forAction: (NSString*)  action 

Searches for a set of registered applications that can receive the given items and perform the given action.

This is similar to applicationRegistrationForSendingItems:forAction:, but returns all possible matches rather than a single one. The order of matches returned is currently arbitrary, but this may change in a future release of SwapKit.

If you specify nil for the action, kILSwapDefaultAction will be used.

The returned array never contains the currently running application. If you want to get the currently running application's registration, use registrationForApplicationWithIdentifier: with the current app's identifier instead.

Returns:
An array of registration dictionaries for all found applications. If none is found, an empty array will be returned.
See also:
- applicationRegistrationForSendingItems:forAction:
- sendItems:forAction:toApplicationWithIdentifier:

Definition at line 351 of file ILSwapService.m.

- (NSDictionary *) applicationRegistrationForSendingItems: (NSArray*)  items
forAction: (NSString*)  action 

Searches for a registered application that can receive the given items and perform the given action.

This is the same algorithm described for the sendItems:forAction:toApplicationWithIdentifier: method when the application identifier is nil.

If you specify nil for the action, kILSwapDefaultAction will be used.

The returned registration is guaranteed to never refer to the currently running application.

Returns:
The registration dictionary for the right application, if found, or nil if no such application is registered with SwapKit.
See also:
- sendItems:forAction:toApplicationWithIdentifier:

Definition at line 332 of file ILSwapService.m.

- (BOOL) canSendItems: (NSArray*)  items
forAction: (NSString*)  action 

Returns YES if there is at least one app, other than the current one, that can receive the given items and action, NO otherwise.

Using this method is more efficient than inspecting the return value of applicationRegistrationForSendingItems:forAction: and allApplicationRegistrationsForSendingItems:forAction:.

If you specify nil for the action, kILSwapDefaultAction will be used.

Returns:
The registration dictionary for the right application, if found, or nil if no such application is registered with SwapKit.
See also:
- sendItems:forAction:toApplicationWithIdentifier:

Definition at line 342 of file ILSwapService.m.

+ (BOOL) didFinishLaunchingWithOptions: (NSDictionary*)  options  

Convenience method for performing startup actions.

It will perform the following upon the swap service instance:

Parameters:
options The same dictionary that was passed to the application:didFinishLaunchingWithOptions: call on the application delegate.

Definition at line 88 of file ILSwapService.m.

+ (BOOL) handleOpenURL: (NSURL*)  u  

Convenience method that calls performActionsForURL: on the swap service instance.

Returns YES if performActionsForURL: acted upon the URL, NO otherwise. (This allows you to ignore SwapKit-handled URLs.)

Definition at line 109 of file ILSwapService.m.

- (BOOL) performActionsForURL: (NSURL*)  u  

Called to perform appropriate delegate method calls based on the given URL.

Returns YES if it has performed any action based on the URL (such as calling a delegate method), NO otherwise. Calling delegate methods requires having called registerWithAttributes:update: since the app launched; otherwise, this method will always return NO.

Usually, you don't call this method directly. Instead, you use the didFinishLaunchingWithOptions: method from the application:didFinishLaunchingWithOptions: method of your app delegate, and the handleOpenURL: method from the application:handleOpenURL: method of your app delegate, which automatically call this method if needed.

See also:
+ didFinishLaunchingWithOptions:
+ handleOpenURL:

Definition at line 367 of file ILSwapService.m.

- (void) registerWithAttributes: (NSDictionary*)  a
update: (BOOL)  update 

Registers this app with the swap service.

Most methods of this class DO NOT WORK unless this method is called first with valid attributes. Methods that only work after registration are noted in their documentation.

Usually, you don't call this method directly. Instead, you use the didFinishLaunchingWithOptions: method from the application:didFinishLaunchingWithOptions: method of your app delegate, which automatically registers your app using registration attributes found in your Info.plist file at the kILSwapServiceRegistrationInfoDictionaryKey.

Parameters:
a A dictionary containing app registration keys and values. If values are not supplied for some app registration keys, defaults may be used during registration instead.
update If YES, any current application's registration will be removed and replaced with this one. If NO, then the current registration will not be replaced, if it exists. Note that this method may try to perform maintenance operations upon the application catalog anyway (for instance, clearing unwanted multiple registrations for this app) even if this argument is set to NO.
See also:
+ didFinishLaunchingWithOptions:

Definition at line 148 of file ILSwapService.m.

- (BOOL) sendItem: (ILSwapItem*)  item
forAction: (NSString*)  action
toApplicationWithIdentifier: (NSString*)  appID 

Sends one item to the application with the given identifier.

This is a convenience method for sendItems:forAction:toApplicationWithIdentifier: for sending a single item; see the docs for that method for more information.

Definition at line 414 of file ILSwapService.m.

- (BOOL) sendItems: (NSArray*)  items
forAction: (NSString*)  action
toApplicationWithIdentifier: (NSString*)  ident 

Sends the given items to the application with the given identifier.

This method behaves as follows:

  • if an app ID is specified (non-nil), its registration will be used to send the items to it.
  • if no app ID is specified, the first app that supports receiving their item type for the given action will receive the items. If there's more than one item, and there is an app that has the kILAppSupportsReceivingMultipleItems set to YES, it's preferred; otherwise, only the first item will be sent to the first app that supports that type, if any. Note that apps that do not support the given action are not considered.

Passing nil for the action is the same as passing kILSwapDefaultAction.

The items array must contain ILSwapItem instances only. This is a change from 1.0, which could contain ILSwapItems or raw values.

SwapKit might elect to send your request asynchronously. In this case, this method will return YES, and the sendingAsynchronously property will be YES for the duration of the send. See also ILSwapServiceDelegate for delegate methods that are called in this case.

Returns:
YES if the item was (or is going to be) dispatched to an app, NO otherwise.
Parameters:
items An array of items, as specified above.
action The action to be performed upon the items by the target application. Can be nil; kILSwapDefaultAction will be used in that case.
ident The application identifier for the target application, or nil to send to the first app that can handle the specified items, type and action.

Definition at line 419 of file ILSwapService.m.

- (BOOL) sendRequestWithAttributes: (NSDictionary*)  attributes
toApplicationWithRegistration: (NSDictionary*)  reg 

This is the primitive request-sending method.

It will send a request with the given attributes to the application whose registration dictionary is passed in.

This method does no checking -- it is assumed that this method is called with an attributes dictionary that will be successfully parsed by another app, either via its delegate method or via SwapKit's built-in checks. sendItems:forAction:toApplicationWithIdentifier: uses this method to send appropriately-formatted requests; it is preferred that you use that method, as it also takes care of placing the items in external storage (such as a pasteboard) and manages that storage's lifetime.

Returns:
YES if the request was dispatched, NO otherwise. (This only happens in cases of force majeoure -- eg the app does not have a URL scheme for receiving because the registration contains incorrect data.)

Definition at line 447 of file ILSwapService.m.


Property Documentation

- (NSDictionary *) applicationRegistrations [read, assign]

Returns all application registrations.

The returned dictionary uses application identifiers as keys, and registration dictionaries as their associated values. These contain any number of registration keys as specified in App Registration Keys, and may contain the registration for this app if registerWithAttributes:update: was called at least once from it.

Definition at line 203 of file ILSwapService.h.


The documentation for this class was generated from the following files:
 All Classes Functions Properties

Generated on Tue Mar 2 13:01:50 2010 for SwapKit by  doxygen 1.6.1