<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/IOService",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@IOService"
  },
  "title" : "IOService"
}
-->

# IOService

The base class for managing the setup and registration of your driver.

```
class IOService;
```

## Overview

An [`IOService`](/documentation/DriverKit/IOService) object is the base class the system uses to represent all devices and device-related interfaces. When the user plugs in a device, the system creates one or more service objects to manage interactions with that device. One service object represents the device itself, and additional service objects represent the interfaces or communication protocols that the device supports. For example, the driver for a USB camera that supports multiple video and audio protocols might define different service objects for each protocol.

When the user plugs in a device, the system looks for the service objects that best match the device’s capabilities. Apple’s built-in driver families support most device types and a large array of standard interfaces. You provide custom service objects to support your device’s custom behaviors.

In most cases, you subclass a child of [`IOService`](/documentation/DriverKit/IOService) such as <doc://com.apple.documentation/documentation/USBDriverKit/IOUSBHostInterface>, instead of [`IOService`](/documentation/DriverKit/IOService) itself. Use the methods of this class to do the following:

- Handle the initialization, setup, and teardown of your driver.
- View and manage the I/O Registry entry for the device or interface.
- Configure the dispatch queue on which to execute your code.
- Respond to power-level changes

For additional information about how to implement services for a particular type of device, see the service subclasses in <doc://com.apple.documentation/documentation/HIDDriverKit>, <doc://com.apple.documentation/documentation/USBDriverKit>, <doc://com.apple.documentation/documentation/NetworkingDriverKit>, <doc://com.apple.documentation/documentation/SerialDriverKit>, and <doc://com.apple.documentation/documentation/USBSerialDriverKit>.

### Adding Member Variables to Your Custom Subclass

Don’t declare custom member variables directly in your [`IOService`](/documentation/DriverKit/IOService) subclass. Instead, DriverKit requires you to define all variables in a separate structure. During initialization, allocate a block of memory for that structure and assign that block to the system-provided `ivars` variable of your service class. The following code example shows you how to define the structure and allocate it in the [`init`](/documentation/DriverKit/IOService/init) method of your service class.

```objc
struct MyCustomKeyboardDriver_IVars
{
    OSArray *elements;
    
    struct {
        OSArray *elements;
    } keyboard;
};

bool MyCustomKeyboardDriver::init()
{
   if (!super::init()) {return false;}
    
   // Allocate memory for the instance variables.
   ivars = IONewZero(MyCustomKeyboardDriver_IVars, 1);
   if (!ivars) {return false;}
    
exit:
   return true;
}
```

Deallocate any memory that you allocate for your custom variables in the [`free`](/documentation/DriverKit/IOService/free) method of your class.

## Topics

### Running the Service

[`virtual bool init();`](/documentation/DriverKit/IOService/init)

Handles the basic initialization of the service.

[`virtual kern_return_t Start(IOService *provider);`](/documentation/DriverKit/IOService/Start)

Starts the current service and associates it with the specified provider.

[`virtual kern_return_t Stop(IOService *provider);`](/documentation/DriverKit/IOService/Stop)

Stops the service associated with the specified provider.

[`virtual void free();`](/documentation/DriverKit/IOService/free)

Performs any final cleanup for the service.

### Registering the Service with IOKit

[`virtual kern_return_t RegisterService();`](/documentation/DriverKit/IOService/RegisterService)

Starts the registration process for the service and performs any additional matching.

[`virtual kern_return_t SetName(const IOServiceName name);`](/documentation/DriverKit/IOService/SetName)

Sets the name of the service in the system’s registry.

[`virtual kern_return_t GetRegistryEntryID(uint64_t *registryEntryID);`](/documentation/DriverKit/IOService/GetRegistryEntryID)

Returns the registry ID for the current service.

[`typedef char[128] IOServiceName;`](/documentation/DriverKit/IOServiceName)

A string type for setting the name of the service in the system’s registry.

### Managing the Registry Properties

[`virtual kern_return_t CopyProperties(OSDictionary **properties);`](/documentation/DriverKit/IOService/CopyProperties)

Returns the registry properties associated with the current service.

[`virtual kern_return_t SetProperties(OSDictionary *properties);`](/documentation/DriverKit/IOService/SetProperties)

Sends the dictionary of properties to the current service object.

[`virtual kern_return_t SearchProperty(const IOPropertyName name, const IORegistryPlaneName plane, uint64_t options, OSContainer **property);`](/documentation/DriverKit/IOService/SearchProperty)

Searches for a property with the specified name in the current service or one of its parent services, and returns the corresponding value.

[`typedef char[128] IOPropertyName;`](/documentation/DriverKit/IOPropertyName)

A string type for specifying the name of a property in the system’s registry.

[`typedef char[128] IORegistryPlaneName;`](/documentation/DriverKit/IORegistryPlaneName)

A string type for specifying the name of a plane in the system’s registry.

[Search Options](/documentation/DriverKit/3325572-search_options)

Options to apply when searching for registry properties.

### Configuring Additional Dispatch Queues

[`virtual kern_return_t SetDispatchQueue(const IODispatchQueueName name, IODispatchQueue *queue);`](/documentation/DriverKit/IOService/SetDispatchQueue)

Associates a custom dispatch queue with the service and assigns the specified name to it.

[`virtual kern_return_t CopyDispatchQueue(const IODispatchQueueName name, IODispatchQueue **queue);`](/documentation/DriverKit/IOService/CopyDispatchQueue)

Gets the dispatch queue with the specified name from the current service.

### Responding to Power-Level Changes

[`virtual kern_return_t SetPowerState(uint32_t powerFlags);`](/documentation/DriverKit/IOService/SetPowerState)

Updates the service in response to power-related changes for a provider.

[`virtual kern_return_t ChangePowerState(uint32_t powerFlags);`](/documentation/DriverKit/IOService/ChangePowerState)

Changes the device’s power state to the specified level.

[Service Power Capabilities](/documentation/DriverKit/3325571-service_power_capabilities)

Constants that indicate the power state of a device.

### Creating a New Service

[`virtual kern_return_t NewUserClient(uint32_t type, IOUserClient **userClient);`](/documentation/DriverKit/IOService/NewUserClient)

Requests the creation of a new user client for the service.

[`virtual kern_return_t Create(IOService *provider, const IOPropertyName propertiesKey, IOService **result);`](/documentation/DriverKit/IOService/Create)

Requests the creation of a new service object.

### Instance Methods

[`virtual kern_return_t AdjustBusy(int32_t delta);`](/documentation/DriverKit/IOService/AdjustBusy)

[`virtual kern_return_t ClientCrashed(IOService *client, uint64_t options);`](/documentation/DriverKit/IOService/ClientCrashed)

[`virtual IOReturn ConfigureReport(OSData *channels, uint32_t action, uint32_t *outCount);`](/documentation/DriverKit/IOService/ConfigureReport)

[`virtual kern_return_t CopyName(OSString **name);`](/documentation/DriverKit/IOService/CopyName)

[`virtual kern_return_t CopyProviderProperties(OSArray *propertyKeys, OSArray **properties);`](/documentation/DriverKit/IOService/CopyProviderProperties)

[`virtual kern_return_t CopySystemStateNotificationService(IOService **service);`](/documentation/DriverKit/IOService/CopySystemStateNotificationService)

[`virtual kern_return_t CoreAnalyticsSendEvent(uint64_t options, OSString *eventName, OSDictionary *eventPayload);`](/documentation/DriverKit/IOService/CoreAnalyticsSendEvent)

[`virtual kern_return_t CreateDefaultDispatchQueue(IODispatchQueue **queue);`](/documentation/DriverKit/IOService/CreateDefaultDispatchQueue)

[`virtual kern_return_t GetBusyState(uint32_t *busyState);`](/documentation/DriverKit/IOService/GetBusyState)

[`IOService * GetProvider() const;`](/documentation/DriverKit/IOService/GetProvider)

[`virtual kern_return_t JoinPMTree();`](/documentation/DriverKit/IOService/JoinPMTree)

[`virtual kern_return_t RemoveProperty(OSString *propertyName);`](/documentation/DriverKit/IOService/RemoveProperty)

[`virtual kern_return_t RequireMaxBusStall(uint64_t maxBusStall);`](/documentation/DriverKit/IOService/RequireMaxBusStall)

[`virtual IOReturn SetLegend(OSArray *legend, bool is_public);`](/documentation/DriverKit/IOService/SetLegend)

[`virtual kern_return_t SetPowerOverride(bool enable);`](/documentation/DriverKit/IOService/SetPowerOverride)

[`virtual kern_return_t StateNotificationItemCopy(OSString *itemName, OSDictionary **value);`](/documentation/DriverKit/IOService/StateNotificationItemCopy)

[`virtual kern_return_t StateNotificationItemCreate(OSString *itemName, OSDictionary *value);`](/documentation/DriverKit/IOService/StateNotificationItemCreate)

[`virtual kern_return_t StateNotificationItemSet(OSString *itemName, OSDictionary *value);`](/documentation/DriverKit/IOService/StateNotificationItemSet)

[`virtual void Stop_async(IOService *provider);`](/documentation/DriverKit/IOService/Stop_async)

[`virtual kern_return_t StringFromReturn(IOReturn retval, OSString **str);`](/documentation/DriverKit/IOService/StringFromReturn)

[`virtual kern_return_t Terminate(uint64_t options);`](/documentation/DriverKit/IOService/Terminate)

[`virtual IOReturn UpdateReport(OSData *channels, uint32_t action, uint32_t *outElementCount, uint64_t offset, uint64_t capacity, IOMemoryDescriptor *buffer);`](/documentation/DriverKit/IOService/UpdateReport)

### Type Methods

[`static OSDictionary * CreateKernelClassMatchingDictionary(OSString *className, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateKernelClassMatchingDictionary-9b28)

[`static OSDictionary * CreateKernelClassMatchingDictionary(const char *className, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateKernelClassMatchingDictionary-3uqly)

[`static OSDictionary * CreateNameMatchingDictionary(OSString *serviceName, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateNameMatchingDictionary-2nzta)

[`static OSDictionary * CreateNameMatchingDictionary(const char *serviceName, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateNameMatchingDictionary-206ej)

[`static OSDictionary * CreatePropertyMatchingDictionary(const char *key, OSObjectPtr value, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreatePropertyMatchingDictionary-4tuca)

[`static OSDictionary * CreatePropertyMatchingDictionary(const char *key, const char *stringValue, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreatePropertyMatchingDictionary-6o4ss)

[`static OSDictionary * CreateUserClassMatchingDictionary(OSString *className, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateUserClassMatchingDictionary-4gpbj)

[`static OSDictionary * CreateUserClassMatchingDictionary(const char *className, OSDictionary *matching);`](/documentation/DriverKit/IOService/CreateUserClassMatchingDictionary-60ptx)

### Instance Methods

[`virtual kern_return_t CallPlatformFunction(OSString *functionName, bool waitForFunction, OSDictionary *inParam, OSDictionary **outParam);`](/documentation/DriverKit/IOService/CallPlatformFunction)

[`virtual kern_return_t CreatePMAssertion(uint32_t assertionBits, uint64_t *assertionID, bool synced);`](/documentation/DriverKit/IOService/CreatePMAssertion)

[`virtual kern_return_t ReleasePMAssertion(uint64_t assertionID);`](/documentation/DriverKit/IOService/ReleasePMAssertion)

## Relationships

### Inherits From

[`OSObject`](/documentation/DriverKit/OSObject)

### Inherited By

[`IOUserServer`](/documentation/DriverKit/IOUserServer)

[`IOUserClient`](/documentation/DriverKit/IOUserClient)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)