UILocalNotification issue with past dates - iphone

I am making a reminder app, if there aren't a million out there.
I let the user specify a time to remind him of a to-do task.
So lets say the user specifies that he needs to be reminded at 9:00am every Monday.
When he closes the app and its goes in the background I create a UILocalNotification fire time.
at 9:00am on next Monday the user gets the notification.
If he launches my app and adds another reminder for some other day/time (not important) and closes my app by clicking on the home button then he gets a notification right away.
This is because the first notification was set to past Monday date
How can I avoid this yet still deliver a notification next monday?
I found this by googling
"If you specify a date that is in the past (or nil) the notification is delivered immediately. "

So, here's what I got from your question:
User makes repeating event for 9:00AM every Monday
You schedule a single local notification for the next occurring Monday at 9:00AM
One Monday at 9:00AM occurs; the users's event fires
User makes another arbitrary event
The users's first event fires, as if it was Monday at 9:00AM, presumably because Monday at 9:00AM has already happened once
In order to resolve this, you want to make sure you're doing both of these things:
Make sure you're releasing the UILocalNotification.
//Manual Memory Management
[yourLocalNotif release];
//Automatic Reference Counting
yourLocalNotif = nil;
Make sure rescheduling your repeating events for the next occurring time.
If this isn't quite what you're looking for, post some code and I'll try and reevaluate :)

Related

How to send notification when users don't open app?

I'm working on an ionic project.
If users don't open the application for a long time after downloading my app, I'd like to send them local notification.
For example, I will send a notification if it does not open for 3 days. But I couldn't figure out how.
Can you help me?
You can use the following to send notifications from server:
Create one table in your database to track user activities.
Add columns as userId, lastActivity to store the time of the user's activity.
Update the lastActivity column whenever the user opens the app.
Write one scheduler which will run at a specific time every day.
In the scheduler write a logic to get data from UserActivity table and compare the time stored in the table with your current time.
If the time difference is greater than 3 days then send a notification to that user.
For local notifications here is a way:
Whenever user open's the app schedule the local notification of after 3 days from current date. ( Make sure to remove previously schedule notification before adding new one. )
In this case if user open the app notification will reschedule automatically else notification will fire based on last schedule of it.
You can create a system in which you track user like ,
if user's opens your App then you must update true value for that user with time in your database and now you can compare current time with user's time value and if its more then 3 days you must send notification to that user.

How to execute a facebook notification after a certain amount of time?

I am new to Facebook development and I am wondering how I can delay execution of an app notification by a given amount of time (days)?
At https://developers.facebook.com/docs/games/notifications or via Google I can't find anything regarding delaying notifications, everything seems to happen immediately.
What I am trying to achieve is that when a facebook app is loaded, I will add a notification to be executed in x days so that the user is reminded of returning to the app then.
I will do this every time the app loads, overwriting the existing notification that was still to be executed.
By that, the user will get the notification only when he really is not logged in for x days.
I'd like to solve that through Facebook alone and not through timers on the server. Can it be done?
There is no way to send delayed notifications, you need to do that on your own. For example, with a Cron Job that checks for the timestamp of the last login every day. Creating a new delayed notification (and deleting the old one) whenever the user logs in would be a weird solution anyway...Those things are usually done with Cron Jobs, there is no need to use the Facebook API when you donĀ“t need it.

UILocalNotification shows 400 badges

I am scheduling a UILocalNotification for an interval. Basically I wanted a notification to be triggered every x days on this app. So the way I did it is to schedule a bunch of notifications at once. So say it's every 2 days, then I do a calculation of the dates every 2 days from now for a year. I am not sure if this is the right and most efficient solution to it, but from researching online, this is what I get I need to do.
The issue is that when the notification fires and I open the app, the badges count goes up to 500, which I think is the number of all future notifications I've scheduled. How is this even possible> Shouldn't the badge only show the number of notifications before the timestamp?
The badge number does not show a number of notifications, but the badge value that you set as notification payload.

Does iOS invalidates localNotifications if the user modifies the date/time

If current date is 20-November-2012 9:00 AM, in my app if I schedule a local notification with firedate say 21-November-2012 10:00 AM and run my application and if I modify the date/time in settings to some previous date say 18-November-2012 I will get the notification properly when the date/time reaches the firedate.
But if I change the date/time to any upcoming date say 30-November-2012 10::PM in device settings I am not getting the notification. Does iOS invalidates localNotifications if the user sets the the date/time to any upcoming date.
When you fire a LocalNotification that notification will get registered into the OS.OS present the notification on time.You can see the notifications your App has registered using the code
`[[UIApplication sharedApplication] scheduledLocalNotifications]`
You CANT edit any notification that is already registered in the OS.
If you want to edit any notification , cancel the previous notification and fire a new one using the updated firedate.
I never understood how you get a notification in 18-November-2012 if the current date is 20-November-2012 9:00 AM.

How to schedule a local notification if an action hasn't been made?

I would like to schedule a local notification to fire at 7pm everyday IF a certain condition is met (the user hasn't entered daily data).
How do I go about doing this?
Just break it up into 3 cases:
It's before 7pm, and the user hasn't entered their daily data yet
It's before 7pm, and the user has entered their daily data
It's after 7pm
In case 1, you set up a notification to go off at 7pm today, and then repeat every day.
In cases 2 and 3, you set up a notification to go off at 7pm tomorrow, and then repeat every day.
The code to create and schedule the notification looks like this:
UILocalNotification *dailyNotification = [[UILocalNotification alloc] init];
dailyNotification.fireDate = nextReminderTime; // set this to 7pm today or tomorrow
dailyNotification.timeZone = [NSTimeZone defaultTimeZone];
dailyNotification.repeatInterval = NSDayCalendarUnit;
dailyNotification.soundName = UILocalNotificationDefaultSoundName;
dailyNotification.alertBody = #"You need to enter data for today.";
Of course, if you set up an alert for 7pm today, then the user opens the app and enters data before 7pm, the notification for today needs to be cancelled.
Alternatively (this is what I did in a similar situation), you can cancel all the notifications with [[UIApplication sharedApplication] cancelAllLocalNotifications]; and set them up again from scratch based on the application state every time the app is about to go into the background (i.e., in UIApplication applicationDidEnterBackground:. This is simpler since you don't have to think about what notifications you set up before.
Scheduling local notifications in iOS is fairly simple - Apple has a good example of how to do it: https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW13
I'm assuming that the criteria to "enter daily data" is happening in your app, right? If so, then you'll basically just schedule local notifications for 7PM each day, and then if a user does enter daily data, you'll just cancel the notification for that day. I've found the local notification scheduling to be a bit finicky, so I would probably cancelAllLocalNotifications and then reschedule them all.
Keep in mind that apps are limited to only being able to have 64 scheduled local notifications at once. So theoretically, you could schedule 64 days into the future (since you're just having one notification per day). I'd be cautious with that though, since it may really annoy users. I'd maybe only do it for a few day or a week at a time, since if they aren't opening the app after a few reminders, they may have lost interest.