I am implementing an iOS8 app that runs in the background and sends a notification that asks a question every 10 mins for 3 hours. I have heard that running timers in the background for 3 hours cannot be done because the app will be suspended after a couple of minutes of going the background state. Is that true? If not will the appstore accept such an app?
There is no point for sending local notificatiosn for 3 hours in background.
Best option would be to prepare a logic which will will create a loop and schedule multiple local notification for 3 hours for example you can schedule n notifications for m duration. This way even your app will be suspended you will be getting local notifications and you can unregister all notification if user open the app.
And regarding your second question: There is no relation with appstore policy for scheduling local notifications in background.
NSDate *newDate = [[NSDate date] dateByAddingTimeInterval:totalDuration];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = newDate;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
This is just a rough code that you can schedule localNotifications by creating a loop with certain timeintervals. Just put your own logic ie 10 mins for 3 hours and supply newDate by adding time interval - 10*60secs
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.