简体   繁体   中英

Avoiding Local Push notification to fire after changing time

In my app, I want to send a Local Push notification every 30 minutes. One way is to just configure local push notification and fire it. However there is a possibility that user can change his time and move forward 30 minutes. In this way a cheat can be done.

I want to configure my app so that notification only occur after 30 minutes. How can I do that. My app does communicate with server and can get its timestamp but I want to do things which don't use much server resources.

The only way I can think of to detect a user altering the system clock is as follows:

  1. When app launches, ask your server the time and note the difference between that and [NSDate date] . Persist that as [NSNumber numberWithFloat:serverOffset];
  2. Implement a method like - (BOOL)deviceClockChanged that asks the server again and compares to the persisted value. If the difference is greater than some small tolerance for clock drift + latency on the synch request, then you can conclude that the clock was changed. Do all this in UTC so it works independent of user travels between time zones.
  3. Consider this: if the user wants badly enough to fool your app about the time in order to delay a notification, messing up the rest of his phone, maybe you ought to just let him edit the notification schedule.

I can supply code examples for points 1 and 2 if you want, and if you want I can supply some @"alert text" for point 3 that will make the user feel really guilty about editing his notifications.

My original answer here. If you choose to let user edit notifications, these methods will be key... UIApplication has a property:

NSArray *scheduledLocalNotifications;

and implements:

- (void)cancelLocalNotification:(UILocalNotification *)notification

So to change one, cancel it, then reschedule it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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