I am having a problem with adding homes with HMHomeManager. I can call the function add
well, but HMHomeManager does not return
func homeManager(manager: HMHomeManager!, didAddHome home: HMHome!) {
println("\(__FUNCTION__)")
}
I am sure I already assigned the delegate of homeManager. Below is my code:
class ViewController: UIViewController, HMHomeManagerDelegate {
var manager: HMHomeManager
required init(coder aDecoder: NSCoder) {
manager = HMHomeManager()
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Actions
@IBAction func home1Pressed(sender: UIButton) {
manager.addHomeWithName("Home12", completionHandler: {
(home:HMHome!, error:NSError!) -> Void in
if error != nil {
println("error: \(error)")
}
else {
println("no error")
}
})
}
@IBAction func home2Pressed(sender: UIButton) {
manager.addHomeWithName("Home23", completionHandler: {
(home:HMHome!, error:NSError!) -> Void in
if error != nil {
println("error: \(error)")
}
else {
println("no error")
}
})
}
// MARK: - HMHomeManagerDelegate
func homeManagerDidUpdateHomes(manager: HMHomeManager!) {
println("\(__FUNCTION__)")
}
func homeManagerDidUpdatePrimaryHome(manager: HMHomeManager!) {
println("\(__FUNCTION__)")
}
func homeManager(manager: HMHomeManager!, didAddHome home: HMHome!) {
println("\(__FUNCTION__)")
}
func homeManager(manager: HMHomeManager!, didRemoveHome home: HMHome!) {
println("\(__FUNCTION__)")
}
}
Note that: when I first run this code, homeManagerDidUpdateHomes
is called which proves to me that homeManager.delegate=self is correct
In this code, after I pressed button1 (home1Pressed
triggered) and button2 (home1Pressed
triggered), home12
and home23
are created. I know this because next time I run this code, the output is:
homeManagerDidUpdateHomes
homes: [[ name = Home1, primary : Yes ], [ name = Home12, primary : No ], [ name = Home23, primary : No ]]
But Why homeManager(manager: HMHomeManager!, didAddHome home: HMHome!
is not called when I pressed button1 and button2? I cannot figure it out, for 2 days.
Thanks,