UILocalNotification Problem - iphone

I have a local notification that I would like to fire every 5 minutes. I use:
localNotif.repeatInterval = NSMinuteCalendarUnit
that will have the notification happen once every minute. I can't figure out how to get this to happen every 5 minutes or whatever other >1 minutes interval. I've tried:
localNotif.repeatInterval= 5 * NSMinuteCalendarUnit
and that doesn't work. Can anyone help me to solve this problem.

Check out this blog http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html
Has a tutorial on how to repeat notifications with an xcode project.
Also maybe it is worth using
NSLog(#"Count: %i", [[[UIApplication sharedApplication] scheduledLocalNotifications] count]);
To check how many notifications your app has registered?

jissa you can't set a 5 minute interval by doing a 5 * NSMinuteCalendarUnit. The current implementation of UILocalNotification does not allow you to fine tune the interval. So you're stuck with every second, every minute, every hour, every day, every week, every month... etc etc.
I've filed a bug report/enhancement at http://bugreport.apple.com/
You may take a look at my report archived at Open Radar: http://openradar.appspot.com/radar?id=759402
According to Marco, developer of Instapaper, Apple prioritizes enhancement and feature requests partly based on how many developers are requesting them.
If this feature is important to you I urge you to file a report as well.

Related

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:
When app launches, ask your server the time and note the difference between that and [NSDate date]. Persist that as [NSNumber numberWithFloat:serverOffset];
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.
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.

Schedule UILocalNotifications for a particular week of a month

I am scheduling UILocalNotifications in my project. At present I am scheduling the notification for the daily basis. Now the client has asked to do particular scenarios like scheduling for every second week. Is there a way to do this? Please can any one suggest a solution.
Thanks In Advance
The answer provided here can be adjusted to suit your needs.
Changing localNotification.repeatInterval = NSDayCalendarUnit; to localNotification.repeatInterval = NSWeekCalendarUnit; (after extracting it out using NSDateComponents) will be a start.
Use Ekeventkit store to show alert on particular dates/days etc.
You should go through Apple documentation

Determine if day change has occurred

I would like to create a notifciation that occurs every time a new day has occurred locally (either while using the app, or if it occurs in between launches). I was wondering what might be the best way to go about observing this change.
While your app is running, you can listen for the UIApplicationSignificantTimeChangeNotification notification and test the current day when you receive that. When your app quits, you can save the current day to your preferences, and when the app launches again, you can test the saved day against the current day.
You can get information about the current day using NSDateComponents.
As mentioned in the other thread, as of iOS8, you can also directly listen to NSCalendarDayChangedNotification.
Check out :
Erica Sadun Time Utililties
There are some useful methods there for checking dates.
Alternatively you can look at UILocalNotifcations
You could schedule a local notification with a repeatInterval of one day.
It all depends on what you want to do but those are some options.
I'd probably do two things:
While the app is running, have an NSTimer set to poll the current date [NSDate date] at a given interval. Store the value of the last date someplace (even in the user defaults) and then compare the new time to the stored time to check for a new day.
When closing/quitting the app, store the current date and time in the same manner above. Then, when launching the app or bringing it to the foreground, check the current date against the stored date.
NSDateComponents, NSCalendar and NSDate will come in handy for this.

How to set LocalNotification repeat each two minutes?

I'm using LocalNotication to set schedule Alarm. atribute repeatInterval allow me to set repeat each minute, each hour.. But I want to set repeat each two minutes? How can i do?
try looking at this blog posting
http://useyourloaf.com/blog/2010/9/13/repeating-an-ios-local-notification.html
You can schedule 30 alarms. One for each 2nd minute for a whole hour, and set repeatInterval to each hour fo each of the 30 notifications.
I've filed a bug report/enhancement at http://bugreport.apple.com/
You may take a look at my report archived at Open Radar: http://openradar.appspot.com/radar?id=759402
According to Marco, developer of Instapaper, Apple prioritizes enhancement and feature requests partly based on how many developers are requesting them.
If this feature is important to you I urge you to file a report as well.

Local Notifications Custom Time Interval

I'm trying to implement local notifications for a calendar-esque application, and I've hit a barrier with reminder intervals. Local notifications seem to only take NSCalendarUnit constants as repeat intervals ( see http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/occ/instp/UILocalNotification/repeatInterval ), as opposed to the typical NSTimeInterval value.
The application that I'm trying to develop would be severely restricted if I'm limited to NSCalendarUnit constants ( which are listed here: http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html#//apple_ref/doc/c_ref/NSCalendarUnit ). Is there any way that I can set custom time intervals in a local notification?
You have to schedule multiple LocalNotifications separated by your time frame, until they fix that bug. I am pretty sure I saw that someone filed it as a bug in the Apple Developer forums