简体   繁体   English

基于iOS位置的提醒

[英]iOS Location based reminder

i am making an application which has a feature that allows users to create location based notifications to turn the application on/off when they arrive/leave a certain location. 我正在制作一个具有允许用户创建基于位置的通知的功能的应用程序,以便在他们到达/离开某个位置时打开/关闭该应用程序。

Reminders are created (as indicated by the first picture), but are not triggered upon arriving/leaving. 会创建提醒(如第一张图片所示),但在到达/离开时不会触发提醒。 在此处输入图片说明

If on the other hand the user click on the reminder, it kind of adds the address (shown on picture number 2) and is from there on triggered 另一方面,如果用户单击提醒,则它会添加地址(如图2所示),然后从该地址触发 在此处输入图片说明

I was wondering if there is a way to make the Reminder app recognize the address or any other suggestion, that might help me in solving this peculiar problem. 我想知道是否有一种方法可以使Reminder应用程序识别地址或任何其他建议,这可能有助于我解决这个特殊问题。

Thank you in advance, 先感谢您,

BR, Rok BR,Rok

The code that i use is: 我使用的代码是:

EKReminder *reminder = [EKReminder reminderWithEventStore:_eventStore];
reminder.calendar = [_eventStore defaultCalendarForNewReminders];

EKStructuredLocation *location;
NSError *error = nil;
EKAlarm *alarm = [[EKAlarm alloc]init];
reminder.title = @"Turn off Test App";
location = [EKStructuredLocation locationWithTitle:self.addressTextField.text];
[self.addressTextField resignFirstResponder];
alarm.proximity = EKAlarmProximityEnter;
alarm.structuredLocation = location;
[reminder addAlarm:alarm];

[_eventStore saveReminder:reminder commit:YES error:&error];

The problem is that you are failing to set your EKStructuredLocation's geolocation and radius . 问题是您无法设置EKStructuredLocation的geolocationradius All it has is a title. 它只有标题。 That isn't enough to tell the alarm where on earth it is supposed to be! 仅告诉警报应该在地球上的哪个位置还不够!

Example: 例:

location.geoLocation =
    [[CLLocation alloc] initWithLatitude:latit longitude:longit];
location.radius = 10*1000; // metres

请参阅CLLocationManager -startMonitoringForRegion:CLRegion类参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM