iOS Developer Library

Developer

MediaPlayer Framework Reference MPRemoteCommand Class Reference

Options
Deployment Target:

On This Page
Language:

MPRemoteCommand

Conforms To


Import Statement


Swift

import MediaPlayer

Objective-C

@import MediaPlayer;

Availability


Available in iOS 7.1 and later

The MPRemoteCommand class provides methods for adding and removing target-action pairs. These target-action pairs allow the app to respond to events as they occur.

The following are subclasses of MPRemoteCommand:

  • Adds a target and action to a remote command object.

    Declaration

    Swift

    func addTarget(_ target: AnyObject!, action action: Selector)

    Objective-C

    - (void)addTarget:(id)target action:(SEL)action

    Parameters

    target

    The object that is a recipient of the action messages sent by the receiver when the represented remote command occurs. nil is not a valid value.

    action

    A selector identifying a method of a target to be invoked by the action message. NULL is not a valid value.

    Discussion

    Call the addTarget:action: method multiple times to specify multiple target-action pairs. If a specific target-action pair has already been added, the request is ignored. You can add multiple actions to a single target by calling this method multiple times using the same target, but different actions.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later

  • Removes a target from the remote command object.

    Declaration

    Swift

    func removeTarget(_ target: AnyObject!)

    Objective-C

    - (void)removeTarget:(id)target

    Parameters

    target

    The object that currently is a recipient of action messages sent by the receiver when the represented remote command occurs. Specify nil to remove all targets from the receiver.

    Discussion

    Call the removeTarget: method to remove the specified target and all actions associated with the target.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later

  • Removes a target and action from a remote command object.

    Declaration

    Swift

    func removeTarget(_ target: AnyObject!, action action: Selector)

    Objective-C

    - (void)removeTarget:(id)target action:(SEL)action

    Parameters

    target

    The object that currently is a recipient of action messages sent by the receiver when the represented remote command occurs. Specify nil to remove all targets from the receiver.

    action

    A selector identifying a method of a target to be invoked by the action message. Specify NULLto remove all actions from the receiver.

    Discussion

    Call the removeTarget:action: method to remove the specified target-action pair. Passing nil for target matches all targets and passing NULL for action matches all actions.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later

  • Add a target with a handler block for the remote event.

    Declaration

    Swift

    func addTargetWithHandler(_ handler: ((MPRemoteCommandEvent!) -> MPRemoteCommandHandlerStatus)!) -> AnyObject!

    Objective-C

    - (id)addTargetWithHandler:(MPRemoteCommandHandlerStatus (^)(MPRemoteCommandEvent *event))handler

    Parameters

    handler

    A block object to handle the MPRemoteCommandEvent.

    Return Value

    An opaque object associated with the designated handler.

    Discussion

    Call the addTargetWithHandler: method to create an opaque object. Remove the handler created by this method by calling the removeTarget: method using the opaque object created by the addTargetWithHandler: method.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later

  • enabled enabled Property

    Determines if a user can interact with the displayed element.

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(nonatomic, assign, getter=isEnabled) BOOL enabled

    Discussion

    When set to TRUE, the designated element is enabled so users can interact with it.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later

  • Constant indicating the status of a command.

    Declaration

    Swift

    enum MPRemoteCommandHandlerStatus : Int { case Success case NoSuchContent case CommandFailed }

    Objective-C

    typedef NS_ENUM (NSInteger, MPRemoteCommandHandlerStatus ) { MPRemoteCommandHandlerStatusSuccess = 0, MPRemoteCommandHandlerStatusNoSuchContent = 100, MPRemoteCommandHandlerStatusCommandFailed = 200 };

    Constants

    • Success

      MPRemoteCommandHandlerStatusSuccess

      Denotes that the requested command did not generate an error.

      Available in iOS 7.1 and later

    • NoSuchContent

      MPRemoteCommandHandlerStatusNoSuchContent

      Denotes that the requested command could not be executed because the content could not be found.

      Available in iOS 7.1 and later

    • CommandFailed

      MPRemoteCommandHandlerStatusCommandFailed

      Denotes that the requested command could not be executed for any other reason.

      Available in iOS 7.1 and later

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 7.1 and later