Hugh Mbaezue
Hugh Mbaezue

Reputation: 93

UILocalNotification on repeat every one second

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

Answers (4)

Yazid
Yazid

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

Shaik Riyaz
Shaik Riyaz

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

Puneet Sharma
Puneet Sharma

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

novalagung
novalagung

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

Related Questions