Reputation: 93
I have been able to get my iBeacon
app to push local notifications to the users while the app runs in background mode, but for some reason this notification keeps on repeating at every one second interval,
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];
}
I just want this notification to be displayed only once to the user when they enter the region.
Upvotes: 0
Views: 831
Reputation: 968
iOS ranges every second, so it sounds like your code is in the didRangeBeacons
method. You should instead move your UILocalNotification
code to the didEnterRegion
method.
Upvotes: 2
Reputation: 11462
try this . . .
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];
Upvotes: 0
Reputation: 9484
According to your code, you seem to be scheduling two local notifications, because your for
loop should run twice. It implies you are not seeing the repeat of the same notification but two different notifications fired at almost same time. I suggest you go through your logic once again.
The repeatInterval
property of UILocalNotification
object by default is set as 0 i.e. non-repeat. Hence, it is not the case of setting repeatInterval
because you want it to be non-repeating.
Upvotes: 0
Reputation: 11502
use presentLocalNotificationNow
. it makes the notification displayed only once at that time when user enter the region.
[[UIApplication sharedApplication] presentLocalNotificationNow:notice];
Upvotes: 0