LeapDelegateΒΆ

In Objective-C, you can use the LeapListener protocol to receive NSNotifications for Leap Motion events or use the LeapDelegate protocol to designate a single object to handle the events.

Methods:

protocol LeapDelegate-p

The LeapDelegate protocol defines a set of methods that you can implement in a delegate object for a LeapController.

The LeapController calls the delegate methods when Leap events occur, such as when a new frame of data is available.

To use the LeapDelegate protocol, implement a class adopting the LeapDelegate protocol and assign it to a LeapController instance:

MYDelegate *delegate = [[MYDelegate alloc] init];
LeapController *controller = [[LeapController alloc] init];
[controller addDelegate:delegate];

When a new frame of data is ready, the controller calls the [LeapDelegate onFrame:] method. The other Leap events, onInit, onConnect, onDisconnect, onServiceConnect, onServiceDisconnect, onExit, onFocusGained, and onFocusLost are handled in the same manner. The Controller object is multithreaded and calls the LeapDelegate functions on its own threads, not on an application thread.

Using the LeapDelegate protocol is not mandatory. You can also use NSNotifications with a LeapListener object or simply poll the controller object (as described in the LeapController class overview).

Since 1.0

Public Functions


- (void) onConnect:(LeapController *) controller

Called when the LeapController object connects to the Leap software, or when this ListenerDelegate object is added to a controller that is already connected.

Since 1.0
Parameters


- (void) onDeviceChange:(LeapController *) controller

Called when a Leap Motion controller plugged in, unplugged, or the device changes state.

State changes include changes in frame rate and entering or leaving “robust” mode. Note that there is currently no way to query whether a device is in robust mode. You can use Frame::currentFramerate() to get the framerate.

- (void)onDeviceChange:(LeapController *)controller
{
    NSLog(@"Device Changed");
}

Since
1.2
Parameters
  • controller -

    The Controller object invoking this callback function.


- (void) onDeviceFailure:(LeapController *) controller

Called when a Leap Motion controller device is plugged into the client computer, but fails to operate properly.

Get the list containing all failed devices using Controller::failedDevices(). The members of this list provide the device pnpID and reason for failure.

Since
2.2.1
Parameters
  • controller -

    The Controller object invoking this callback function.


- (void) onDisconnect:(LeapController *) controller

Called when the LeapController object disconnects from the Leap software.

The controller can disconnect when the Leap device is unplugged, the user shuts the Leap software down, or the Leap software encounters an unrecoverable error.

- (void)onDisconnect:(LeapController *)controller
{
    NSLog(@"Disconnected");
}

Since 1.0
Parameters


- (void) onExit:(LeapController *) controller

Called when this LeapDelegate object is removed from the LeapController or the controller instance is destroyed.

Note: When you launch a Leap-enabled application in a debugger, the Leap library does not disconnect from the application. This is to allow you to step through code without losing the connection because of time outs.

Since 1.0
Parameters


- (void) onFocusGained:(LeapController *) controller

Called when this application becomes the foreground application.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

- (void)onFocusGained:(LeapController *)controller
{
    NSLog(@"Focus Gained");
}

Since 1.0
Parameters


- (void) onFocusLost:(LeapController *) controller

Called when this application loses the foreground focus.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

- (void)onFocusLost:(LeapController *)controller
{
    NSLog(@"Focus Lost");
}

Since 1.0
Parameters


- (void) onFrame:(LeapController *) controller

Called when a new frame of hand and finger tracking data is available.

Access the new frame data using the [LeapController frame:] function.

- (void)onFrame:(LeapController *)controller
{
     NSLog(@"New LeapFrame");
     LeapFrame *frame = [controller frame:0];
     //...
}

Note, the LeapController skips any pending frames while your onFrame handler executes. If your implementation takes too long to return, one or more frames can be skipped. The controller still inserts the skipped frames into the frame history. You can access recent frames by setting the history parameter when calling the [LeapController frame:] function. You can determine if any pending frames were skipped by comparing the ID of the current frame with the ID of the previous received frame.

Since 1.0
Parameters


- (void) onImages:(LeapController *) controller

Called when new images are available.

Access the NSArray containing the new images using the [LeapController images] function.

- (void)onImages:(LeapController *)controller
{
     NSLog(@"New image list");
     NSArray *images = [controller images];
     //...
}

Since
2.2.1
Parameters
  • controller -

    The Controller object invoking this callback function.


- (void) onInit:(LeapController *) controller

Called once, when the LeapController has finished initializing.

Since 1.0
Parameters


- (void) onServiceChange:(LeapController *) controller

Called when the Leap Motion service is paused or resumed or when a controller policy is changed.

The service can change states because the computer user changes settings in the Leap Motion Control Panel application or because an application connected to the service triggers a change. Any application can pause or unpause the service, but only runtime policy changes you make apply to your own application.

You can query the pause state of the controller with Controller::isPaused(). You can check the state of those policies you are interested in with Controller::isPolicySet().

Since
2.2.1
Parameters
  • controller -

    The Controller object invoking this callback function.


- (void) onServiceConnect:(LeapController *) controller

Called if the Leap Motion daemon/service disconnects from your application Controller.

Normally, this callback is not invoked. It is only called if some external event or problem shuts down the service or otherwise interrupts the connection.

- (void)onServiceConnect:(LeapController *)controller
{
    NSLog(@"Service Connected");
}

Since 1.2
Parameters
  • controller -

    The Controller object invoking this callback function.


- (void) onServiceDisconnect:(LeapController *) controller

Called if the Leap Motion daemon/service disconnects from your application Controller.

Normally, this callback is not invoked. It is only called if some external event or problem shuts down the service or otherwise interrupts the connection.

- (void)onServiceDisconnect:(LeapController *)controller
{
    NSLog(@"Service Disconnected");
}

Since 1.2
Parameters
  • controller -

    The Controller object invoking this callback function.