Push notifications ios - iphone

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.

Related

How to use NSThread with UILocalNotification to show custom view?

I am developing an application of Fake incoming call.
For that, i am right now using local notification.
I am getting notification as per the set time but it gives me the pop up, like a by default notification.
Instead this, i have to show the view from either XIB or by codeing.
So, is there any way to set the custom view with localnotification?
Or can i use NSThread to get the above mentioned output?
If anyother way to get the disered output, then please let me know.
Thanks in advance
This is what i am doing to set the notification.
-(void)addNotification
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
[localNotification setAlertAction:#"Answer"];
[localNotification setAlertBody:[NSString stringWithFormat:#"%#\n\n %#",[txt_CallerName text],[txt_CallerNumber text]]];
[localNotification setHasAction: YES];
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
[alertNotification setHidden:NO];
}
Showing a custom interface on receiving a UILocalNotification is not possible right now. It is possible if you happen to receive the UILocalNotification when your app is in the foreground. But if it is in the foreground, you could show your custom interface regardless.
The way you catch the local notification firing and do something when that happens is by implementing -application:didReceiveLocalNotification: in UIApplicationDelegate. Arguably, it is the answer to your question, but it won't achieve what you're clearly looking for, which is to start your app at a specific point in time by showing custom UI, because it will only happen while the app is already in the foreground.
You can use NSNotificationCenter to throw notification and event occurred just call the notified method and display your custom view.
1.Register the Notification as follows:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(displayCustomView) name:#"EventNotification" object:nil];
2.When event occur notify method as follows:
[[NSNotificationCenter defaultCenter] postNotificationName:#"EventNotification" object:nil];
3.In notified method display your custom view as follows:
-(void)displayCustomView
{
//initialize custom view and display as required.
}

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.

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.

UILocalNotification not showing up in Notification Center when app is in background

I have a GPS app that registers to run in the background. I also show a UILocalNotification when I have finished a process. This correctly shows, and if the app is open, then it also appears in Notification Center (swipe down from top). But, if I call the UILocalNotification when my app is in the background, or the screen is locked, I DO get the notification, but it does NOT show up in Notification Center.
I am correctly registering for notifications in my app delegate (iOS 5 bug workaround):
// Register for notifications
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
Calling the notification:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = msg;
localNotif.alertAction = NSLocalizedString(#"View", nil);
localNotif.soundName = #"alert.caf";
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
Is this a bug? Why would it show up in Notification Center only when my app is open, even though the notification is shown to the user, and not other times?
Are you also using push notifications? I believe there is no need to call registerForRemoteNotificationTypes: if you are only using local.
Check Here
From the look of the code you posted, it does not look like the code would run in the background. It looks like you are trying to present a Local Notification when an even occurs in the background. You can not do this. Local Notifications are meant to be scheduled while the app is running to go off at a later time when the app is not running, and then they will trigger even when the app is closed.
You need to use Push Notifications. Check out Apple's documentation here.
EDIT: Is your app enabled for the notification center in settings?
have you added the UIBackgroundModes key to your Info.plist file ?
You need to have the UIBackgroundModes Key set to location.

How to call the snooze feature on local notification in iOS?

I am implementing an alarm application in iOS with snooze feature.
Local notification is set properly. When I select a particular time it fires at that particular time displaying 2 buttons close and view.
I have renamed the view button as snooze so that when the user clicks on snooze the notification will get repeated after 1 mins.
But I have a problem when the snooze button is clicked it shows properly in the console that it will repeat after 1 min from current time but the notification does not repeat in the console.
What may be the problem.
Please help me in solving this problem.
This is my code:-
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(#"Recieved local Notifications %#",notification.fireDate);
NSDate *date=[notification.fireDate dateByAddingTimeInterval:60];
NSLog(#"date After interval is %#",date);
UILocalNotification *notif=[[UILocalNotification alloc]init];
notif.fireDate=date;
NSLog(#"new notification:%#",notif.fireDate);
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
application.applicationIconBadgeNumber = 0;
}
In the didReceiveLocalNotification I have added because when the snooze button is clicked I want the 1 minute time interval notification to be set and called.
You're initializing a new UILocalNotification, but you not setting anything to be done when it actually fires - no body, or action.
From the Apple documentation,
alertBody - The default value is nil (no alert).
So, when the notification fires there will be no outward alert.
Are any of the application Local Notification callbacks being invoked? (which one, depends on the state of the App)
when ever your got notification application responds to below
method so.put one alertview you got alarm .did you want snooze .
then by that time remove all before notification and recreate notification.
with repeat interval.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//write alert in alert delegate method create new notification object ,
}