Friday, September 30, 2022
HomeiOS Developmentios - 'Operation has been canceled' whereas including a brand new accent...

ios – ‘Operation has been canceled’ whereas including a brand new accent to HomeKit app


I am creating a SwiftUI app for iOS and iPadOS to manage my HomeKit good units, particularly a RGB led strip. I am following this official documentation and I used to be in a position to create new houses utilizing this code:

class HomeStore: NSObject {
    static var shared = HomeStore()
    let homeManager = HMHomeManager()
    var homeDelegates = Set<NSObject>()
    var accessoryDelegates = Set<NSObject>()
}

extension HomeStore {
    func addHome(identify: String) {
        homeManager.addHome(withName: identify, completionHandler: { (residence, error) in
            if let error = error {
                print("Error whereas including a brand new residence named (identify): (error.localizedDescription)")
        }
    })
}

I created one other operate so as to add new accent:

func addAccessory(residence: HMHome, accent: HMAccessory) {
    residence.addAccessory(accent, completionHandler: { error in
        if let error = error {
            print("Error whereas including a brand new accent named (accent.identify) to residence (residence.identify): (error.localizedDescription)")
        }
    })
}

I created additionally one other class and a operate for looking new equipment close by:

class AccessoryListController: NSObject, HMHomeManagerDelegate, HMAccessoryBrowserDelegate {
    static var shared = AccessoryListController()
    let browser = HMAccessoryBrowser()

override init() {
    tremendous.init()
    HomeStore.shared.homeManager.delegate = self
    browser.delegate = self
    }
}

extension AccessoryListController {
    func searchAccessories() -> [HMAccessory] {
        browser.startSearchingForNewAccessories()
        print("Looking out equipment...")
        print("Discovered (browser.discoveredAccessories.depend) equipment")
    
        return browser.discoveredAccessories
    }
}

Thus far all the pieces works accurately. Once I search new equipment, the operate discovers them and prints:

Looking out equipment...
Discovered 1 equipment

After the simulator asks me if I wish to add the brand new accent and it might present me the web page so as to add the HomeKit setup code nevertheless it does not seem. That is the error message:

Error whereas including a brand new accent named Led Strip to residence Casa: Operation has been canceled.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular