2014-01-15 60 views
0

我已經能夠讓我的iBeacon應用本地通知推向用戶,而該應用程序會在後臺運行,但由於某種原因,此通知不斷每一秒的間隔重複,UILocalNotification上重複每隔一秒

UILocalNotification *notice = [[UILocalNotification alloc] init]; 

     for (int i=0; i<=1; i++) 
      { 
      notice.alertBody = @"We just found some great deals in this location!"; 
      notice.alertAction = @"Open"; 

     [[UIApplication sharedApplication] scheduleLocalNotification:notice]; 


     notice.fireDate = [[NSDate date] dateByAddingTimeInterval:0.2]; 
     } 

我只是想,當他們進入該地區,以顯示該通知僅一次給用戶。

+3

'for(int i = 0; i <= 1; i ++)'???真? – matt

+1

你不說這個代碼是如何與你的iBeacon回調綁定的。如果您在回撥範圍內有此設置,則會重複顯示。如果您在監控回調中使用它,則不應無休止地顯示。 – davidgyoung

+0

偉大的答案,謝謝DavidgYoung。我在回調中調用了這個函數,因爲我在邏輯語句中設置了它。 –

回答

0

使用presentLocalNotificationNow。當用戶輸入該地區時,它只會顯示一次通知。

[[UIApplication sharedApplication] presentLocalNotificationNow:notice]; 
0

根據你的代碼,你似乎是安排兩個本地通知,因爲你for循環應該運行兩次。這意味着你沒有看到相同通知的重複,但幾乎同時發出兩個不同的通知。我建議你再次通過你的邏輯。

repeatIntervalUILocalNotification屬性的默認對象被設置爲0,即非重複。因此,不要設置repeatInterval,因爲您希望它不重複。

0

試試這個。 。 。

UILocalNotification *notice = [[UILocalNotification alloc] init]; 
notice.alertBody = @"We just found some great deals in this location!"; 
notice.alertAction = @"Open"; 
notice.fireDate = [[NSDate date] dateByAddingTimeInterval:0.2]; 
[[UIApplication sharedApplication] scheduleLocalNotification:notice]; 
2

iOS範圍每秒鐘,所以它聽起來像你的代碼是在didRangeBeacons方法。您應該將UILocalNotification代碼移至didEnterRegion方法。