HMLocationEvent Sample

吃可爱长大的小学妹 提交于 2019-12-23 20:32:04

问题


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:

  1. To achieve the requirement Do I need to use HMLocationEvent and HMEventTrigger? or is there any alternate?
  2. 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?
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!