2013-03-25 76 views
0

我正在製作一個應用程序,該應用程序具有允許用戶創建基於位置的通知以在應用程序到達/離開特定位置時打開/關閉應用程序的功能。iOS基於位置的提醒

提醒被創建(如第一張圖片所示),但不會在到達/離開時觸發。 enter image description here

如果另一方面,用戶點擊該提示,它種增加了地址(上圖號2所示),並從那裏觸發 enter image description here

我在想,如果有一個讓提醒應用程序識別地址或任何其他建議的方式,這可能有助於我解決這一特殊問題。

謝謝你在前進,

BR, 韓城

,我使用的代碼是:

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]; 
+0

顯示你的代碼!您如何實際創建提醒的基於位置的鬧鐘? – matt 2013-03-25 19:36:32

+0

將代碼添加到主文章 – rcresnik 2013-03-26 10:16:33

回答

3

問題是您未能設置您的EKStructuredLocation的geolocationradius。它只有一個標題。這還不足以告訴警報應該在哪裏!

例子:

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

就是這樣! 感謝您的幫助:) – rcresnik 2013-03-26 19:14:09

+0

您打賭。獲得的教訓(我希望):當你問一個問題時,發佈你的代碼! – matt 2013-03-26 20:25:06

+0

我認爲代碼是好的,因爲我正在通過一個教程,但它不包括這部分。將通知作者以及... :) – rcresnik 2013-03-27 08:36:42

0

CLLocationManager -startMonitoringForRegion:CLRegion類引用。