问题
I am implementing HMLocatinEvent in my HMHome. I am trying the below code but one thing I didn't get is I don't know how to execute functionality like incase if I left home have to switch off all the lights. I didn't find any method related to the actionset. Please correct me if I am wrong.
Requirement: I want to switch off all the HMAccessories incase if I left home.
Questions:
- To achieve the requirement Do I need to use HMLocationEvent and HMEventTrigger? or is there any alternate?
- Incase if I has to use HMLocationEvent and HMEventTrigger how can I perform some action in the actions incase of enter/exit of the specified region?
Do I need to implement the CLLocationManager and delegate methods to use the HMLocationEvent?
HMLocationEvent *locEvent = [[HMLocationEvent alloc] initWithRegion:region1];
region1.notifyOnEntry = YES;
region1.notifyOnExit = YES; CLRegion *region1 = [[CLCircularRegion alloc] initWithCenter:[selectedLoc coordinate] radius:5 identifier:@"Office"]; NSDateComponents *com = [[NSDateComponents alloc] init]; com.second = 1; HMEventTrigger *tr = [[HMEventTrigger alloc] initWithName:eventName.text events:[NSArray arrayWithObject:locEvent] predicate:[HMEventTrigger predicateForEvaluatingTriggerOccurringOnDateWithComponents:com]]; [selectedHome addTrigger:tr completionHandler:^(NSError *err) { }];
Thank you for the valuable time.
回答1:
My concept is to use geofence 1) Create geofence of ur home 2) just get the location of the house and create a fence with 50meters radius 3)Now create a code that listen for exist the geofence area and implement the corresponding code
reference for geo fence
http://www.raywenderlich.com/95014/geofencing-ios-swift
来源:https://stackoverflow.com/questions/32584045/hmlocationevent-sample