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

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.

Related

Set a task for a certain date (iOS app)

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.

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 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.

Push notifications ios

If my app is closed , and the iphone receives a push notification for that app, will it receive it and open the app?
Thanks
No if the message is received it will not open the app.
You app wil get launched if the user selects to view the notification.
Thus if the user does not react to the notifications your app will not be launched.
If your app is already running and in the foreground than the app delegate will receive the notification directly.
Yes it will launch if "View" button is clicked and application will call the delegate method.
If clicked on "close" button it will discard the notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}
For more info http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 and http://mobiforge.com/developing/story/programming-apple-push-notification-services
YES. http://urbanairship.com/products/push-notifications/
when the notification aries that time you open the application that for you can use the following code.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];
// Current date
NSDate *date = [NSDate date];
// Add one second to the current time
NSDate *dateToFire = [date dateByAddingTimeInterval:1];
// Set the fire date/time
[localNotification setFireDate:dateToFire];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
// Setup alert notification
[localNotification setAlertBody:#"Tap to return to TestApp" ];
[localNotification setAlertAction:#"Open TestApp"];
[localNotification setHasAction:YES];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
And more information regarding this thing you can use Refer the Reference.
May this code helping to you.
Yes, when you receive push - it appears as an alert on the screen on appears in the top (you can choose a way in Settings) as a message which will disappear after some seconds. If you click on push notification - it'll open App. But when you receive push, App will not be opened automatically with a receiving a push. Only after user clicks on push.

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.