Set a task for a certain date (iOS app) - iphone

Assume that I create a task today, and say that I want to be reminded of it (via a push notification) 10 days from today. Essentially, how do I constantly keep track of what day it is (even when my app isn't actively being used) to finally recognize when it becomes 10 days from today?

You don't do this.
You would schedule the notification for when it is supposed to happen like this...
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate someDateInTheFuture];
notification.alertBody = #"This is your alert. Do something";
notification.alertAction = #"Alert";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
The notification will then fire when it gets to the date that you set. You don't have to check for it yourself in the app. It just happens.

Related

How to set UINotification for specific days like every Monday and Friday?

I am writing an alarm app. In the app, user can select days from the picker for setting alarm on that day with time. But I don't know to set alarm (UILocalNotification) for specific day in a week (0 - 7).
I just wanted to set fire date of UILocalNotification on specific day like ex. Monday, Friday and Sunday..
I have searched on net and got many similar forums but none of them worked for me.
Any suggestions ?
Set the local notification fireDate for the first notification that should be made. Then set the repeatInterval for the duration between any notification and the next notification.
It would be more helpful if you have included codes which you have tried.
Anyways,
NSDate myOwnDate; // myOwnDate can be a date that is on a specific day. Make sure it is a valid date variable
UILocalNotification* local_notification = [[UILocalNotification alloc] init];
[local_notification setFireDate:myOwnDate];
[local_notification setRepeatInterval:NSWeekCalendarUnit];
[local_notification setAlertBody: #"Your alarm is ringing!"];
UIApplication* app = [UIApplication sharedApplication];
[app scheduleLocalNotification:local_notification];
Pretty straightforward I would say.

Display UIAlertView on certain date?

I was wondering how I'd make a UIAlertView display on a certain date, for example, users download the iPhone application and then on the 12th August, a predetermined UIAlertView displays? How could I do this?
Thanks!
You should take a look at the UILocalNotification API. It allows you to create and schedule local notification for your application, which will then be fired on the desired date, using a badge/popover/sound (same settings as for the remote notification API).
For your case you should specifically take a look at the fire date. Sample code would look moreless like this:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = #"Your message here";
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60*60];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
This will fire a local notification with a "Your message here" text in one hour.

how to notify user in ios, while app is closed/ inbackground

i want to notify the user when a "time" is reached.
for example:
i have an tableview with many rows. this rows are something like reminders where the user can set the date and time of remind.
So in a row the reminder is set to 24 April 12:15.
At this time the App is closed.
So how can i notify the user that this time is reached?
Is there a way to do that without apple push notification service?
Edit 1:
Thanks for answering, here is an example for local notifications:
//This example adds 20 seconds to current time, use it for testing
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *currentDate = [NSDate date];
NSDate *currentDatePlus = [currentDate dateByAddingTimeInterval:20];
localNotification.fireDate = currentDatePlus;
localNotification.alertBody = #"Hallo ayFon User";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
EDIT 2:
//Add this for iOS 5 Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
You have to use the Local Notifications of iOS. They are done in this exact purpose.
You can find documentation here: Local and Push Notification Programming Guide.
You don't have to use Push Notifications - you could use Local Notifications instead. They are similar to Push notifications except that they are generated on the device instead so you don't need a network connection.
This is a fairly common pattern for alarm type apps.

How do I increase the value of applicationIconBadgeNumber during app doesn't run?

How do I increase the applicationIconBadgeNumber by localNotification?
Is it possible to increase the applicationIconBadgeNumber to add [ 1 ] every day by localNotification?
If localNotification doesn't work, how can I change applicationIconBadgeNumber?
It was done by AppName:Count it!
http://itunes.apple.com/app/id443809931?mt=8&ign-mpt=uo%3D4
I asked a question by e-mail to the developer of this application seven months ago.
However, a reply did not come.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = startDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatInterval = NSDayCalendarUnit;
//I don't know the follow code.I want to increase BadgeNumber during repeatInterval
localNotif.applicationIconBadgeNumber = 1++;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
Local notifications can set the application icon badge number. Obviously, the app has to run to schedule the local notification, but does not need to be running to receive it.
The other option, of course, is to use remote notifications.
You can try to use [UIApplication setKeepAliveTimeout:handler:] to execute a function every X seconds (at least 600). In that function you can increase the number.
The setKeepAliveTimeout require to be a VOIP application, so i'm not sure if apple can approve you anyway.

iPhone: How to get notification center to detect date?

I just wrote an application that depends largely on the ability to notify you when a deadline is approaching. It allows the user to type in a specific date in a UITextField (not using a date picker.) I would rather not go through the hassle of setting up push notifications, iOS 5's notification center will work great. But, I'm unsure of how to get the notification center to detect the entered in dates.
I put this code in my didFinishLaunchingWithOptions: method in my view controller:
UILocalNotification *dateNotif = [[UILocalNotification alloc] init];
localNotif.fireDate=[NSDate date];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = #"Event starts in 20 minutes!";
localNotif.alertAction = #"Show me";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication]presentLocalNotificationNow:dateNotif];
[localNotif release];
But I'm not sure where to go from here at all, I'm still really new to this. Any help would be great, thank you!
You need to create a UILocalNotification, set the fireDate appropriately (and set whatever text you want the user to see), then pass it to UIApplication's scheduleLocalNotification:.
The only things you'll need to deal with beyond that are that if your app is already running when the notification fires then the notification centre won't do anything and your application delegate will get a didReceiveLocalNotification:. If the app isn't running but the user chooses to launch it from the alert then you'll get the local notification handed back to your didFinishLaunchingWithOptions:, allowing you to do something relevant.