HomeKit Device Integration in Mobile IoT App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
HomeKit Device Integration in Mobile IoT App
Complex
~5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

HomeKit Device Integration into Mobile IoT App

HomeKit — closed ecosystem, but in 2019 Apple opened HAP (HomeKit Accessory Protocol) and specifications. For mobile app developer this means working with HomeKit.framework on iOS, watchOS and tvOS. Without this — no way: third-party apps control HomeKit devices only via official API, no workarounds.

HomeKit API: Structure and Limitations

Hierarchy: HMHomeManagerHMHomeHMRoomHMAccessoryHMServiceHMCharacteristic. Device (Accessory) provides services (Service) — e.g., smart bulb has HMServiceTypeLightbulb service. Service contains characteristics (Characteristic) — HMCharacteristicTypePowerState, HMCharacteristicTypeBrightness, HMCharacteristicTypeHue.

import HomeKit

class HomeKitManager: NSObject, HMHomeManagerDelegate {
    private let homeManager = HMHomeManager()

    override init() {
        super.init()
        homeManager.delegate = self
    }

    func homeManagerDidUpdateHomes(_ manager: HMHomeManager) {
        guard let primaryHome = manager.primaryHome else { return }
        fetchLightbulbs(in: primaryHome)
    }

    private func fetchLightbulbs(in home: HMHome) {
        let lightbulbs = home.accessories.flatMap { $0.services }
            .filter { $0.serviceType == HMServiceTypeLightbulb }

        for service in lightbulbs {
            if let brightness = service.characteristics.first(where: {
                $0.characteristicType == HMCharacteristicTypeBrightness
            }) {
                brightness.readValue { error in
                    if let error { print("Read error: \(error)") }
                    print("Brightness: \(brightness.value ?? "nil")")
                }
            }
        }
    }
}

Writing Values and Asynchronicity

writeValue(_:completionHandler:) — asynchronous, returns error via callback. iOS 16+ supports async/await via wrapper or directly via HMCharacteristic.writeValue:

func setLightOn(_ isOn: Bool, characteristic: HMCharacteristic) async throws {
    try await characteristic.writeValue(isOn)
}

Command latency via HomeKit — 100-500 ms for local devices, up to 2 seconds via remote (through Apple TV or HomePod as hub). If device behind hub offline, get HMError.accessoryNotReachable (code 6).

State Change Notifications

HAP supports push notifications from devices via enableNotification(true). App subscribes to characteristic changes:

class AccessoryDelegate: NSObject, HMAccessoryDelegate {
    func accessory(_ accessory: HMAccessory,
                   service: HMService,
                   didUpdateValueFor characteristic: HMCharacteristic) {
        if characteristic.characteristicType == HMCharacteristicTypeMotionDetected {
            let motionDetected = characteristic.value as? Bool ?? false
            NotificationCenter.default.post(
                name: .motionDetected,
                object: motionDetected
            )
        }
    }
}

One nuance: notifications arrive only while app in foreground or has background execution permission. For background events use HMEventTrigger — HomeKit automation executed without app participation.

Automation and Triggers

HMEventTrigger allows creating rules directly from app:

let motionCharacteristic = // HMCharacteristic of type MotionDetected
let triggerEvent = HMCharacteristicEvent(
    characteristic: motionCharacteristic,
    triggerValue: true
)

let trigger = HMEventTrigger(
    name: "Motion Detected",
    events: [triggerEvent],
    end: nil,
    recurrences: nil,
    executionConditions: nil
)

let lightCharacteristic = // HMCharacteristic of type PowerState
let action = HMCharacteristicWriteAction(
    characteristic: lightCharacteristic,
    targetValue: true
)

let actionSet = HMActionSet(name: "Turn on light")
// Add action to actionSet, then attach to trigger
home.addTrigger(trigger) { error in
    if let error { print("Trigger error: \(error)") }
}

Triggers execute on Hub (HomePod, Apple TV) and run even when app closed.

Entitlements and App Store

HomeKit requires entitlement com.apple.developer.homekit and NSHomeKitUsageDescription key in Info.plist. Without NSHomeKitUsageDescription app crashes on first HMHomeManager access without warning — common setup mistake.

Testing — only on real device. Simulator doesn't support HomeKit physical accessories; for development use HomeKit Accessory Simulator from Additional Tools for Xcode.

HomeKit integration into existing iOS app with devices for testing takes 2-3 weeks: rights setup, device management layer, automation, background event handling. Cost calculated individually.