Open a specific tab/view when user receives a push notification - iphone

I want to do something like Twitter app: when someone write me I receive the push notification; if I "slide on the notification" the app starts, but not in the normal stream, it starts in a specific view with the tweet that someone wrote me!
In my app I have something like an RSS reader, and the push notification arrives when there is a new news.
So, I want to open the "single news view", and not the main view (that's happening now).
What can I do?
Thanks

You can do two things.
One is to check the launchOptions dictionary of the UIApplicationDelegate method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to see if the app was launched via a user clicking on a notification. If so, then in that method you can push the appropriate view controller onto the stack, just as you would normally with in-app usage.
If the app is already open, but in the background then the same theory applies but instead use the UIApplicationDelegate method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
See this link for information on handling incoming notifications.

Related

How to check for a badge number on app launch on iPhone

How can I check if my app has a badge number. When I send a push notification the users, it add a "1" as the badge number to the icon. I would like to check if there is a badge number when the user launches the app and direct them a view controller.
I'd propably make use of the property applicationIconBadgeNumber of the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions's application.
So, to be clear:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.applicationIconBadgeNumber = 1; /*some number...*/
//or to read the number
int appIconBadge = application.applicationIconBadgeNumber;
}
Hope that helps.
I think you'll need to keep track of it yourself in the app. Your delegate’s application:didFinishLaunchingWithOptions: will be called upon the notification and the user presses the action button and it receives the notification payload.
If you app is running in the foreground, the delegates application:didReceiveRemoteNotification: will be called. In this case you could have an integer value and increment it to keep track of the number of notifications you have. It also receives the notification payload.
Alternately, without knowing anything about your design, you could have a web service that the app could query to determine whatever number of items you are looking for, but this seems much more difficult, and depending on the design you are working with might be unworkable.
Reference:
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

Doing something even if application is closed in iphone

I am developing iphone application where i want to develop feature of taking backup of files inside the application on to the server for every hour even if the application is completely closed.
I have tried to use NSLocalNotification but it is not calling method
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
in appdelegate. The notifier showing alert box with the buttons cancel and view , If I click in view it opens the application but not calling the method. Even if user say cancel then also it should call this method.
So it is not calling web service to take backup of files. Can any one please direct me to link which does the same.
Thanking You,
Rohit Jankar
You really can't do what you want. Since iOS does not allow application to run in the background unless it's is a VOIP client, AudioPlayer or track the user location.
The problem with the solution with UILocalNotification is that iOS handles the notification. When the user clicks cancel your app does not get informed about this. You can only handle the view button clicks.
The-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification is only called if you app is run or is restored from background running.
If you app gets start by the system when you user click view on the Local notification you will need to check if there is a notification in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method:
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
//handle the notification.
}
I am developing iphone application where i want to develop feature of
taking backup of files inside the application on to the server for
every hour even if the application is completely closed.
If you're talking about backing up files to your own server every few hours, there's really no way to do that. On the other hand, there should also be no need to do it when the app isn't running -- if the app isn't running, it can't modify data in its files and there shouldn't be any need to back up. Instead, just make sure that you back up your data periodically when the app is running.
If you just want to make sure that the app's data is backed up somewhere, consider using iCloud. Once you've set up your app to use iCloud, your data will be backed up whenever you update it.

Detect app opening?

I have a Tab bar app with 3 view controllers and I use "viewWillAppear" to detect which view is opend.
When I close the app, it still works "in the background" and when I open the app again "viewWillAppear" is not detecting this opening.
Is there any other option to detect this opening? Thanks
You can observe the UIApplicationWillEnterForegroundNotification or implement applicationWillEnterForeground: in your app delegate.
Firstly, You should see the necessary delegation method in UIApplicationDelegate
When you close application that currently open, It will call this method:
- (void)applicationDidEnterBackground:(UIApplication *)application
After the application has been closed but still in dock, you open them again. In the transition state before entering the application, It will call this method:
- (void)applicationWillEnterForeground:(UIApplication *)application
When the application completely presented on previous state before you closed them. It finally call thid method:
- (void)applicationDidBecomeActive:(UIApplication *)application
If you would like to do something in viewWillAppear you should implement in applicationDidBecomeActive to send some message to your current view or other to do what do you want to do after application became actived.
When your app is resumed from the background, it will receive the applicationWillEnterForground: method. It'll get the applicationDidEnterBackground: when it is suspended too.
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(#"app will enter foreground");
[viewController refresh:NULL];
}
i think this will work.
write this in your app delegate

iOS5 Notification drop-down menu: is there a way to know when the user presses the clear button on my apps notification on the iPhone?

Is there a delegate method or some way to get the event when a user clears my applications notifications from the Notification drop-down menu? The UIApplication delegate
-(void)application:(UIApplication)application didReceiveLocalNotification:(UILocalNotification *)notification
is only called when they select an event from the list but it isn't called when the list is cleared.
No, if a user clears your notification, it's the same as if it never arrived.
If you clear notification or swipe on notification message this method will be called in appdelegate.m file.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//When notification is pressed on background it will enter here
//Get strings based on information on your json payload for example
if([[userInfo objectForKey:#"keyword"] isEqualToString:#"value"]){
//redirect/push a screen here for example
}

How to know the app is invoked from background process or not

Thanks in advance.
I used push notification service in my application.If the app is running in background i am able get the alert view, but the app is in active state it is not displaying alert. Is there any way to display alert.
Actually to display alert i am creating an alert in
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo method.
But there is a problam with this alert i.e., of the app is running in background we will get remote alert at the same time we will get this alert also.
So is there any way to find if the app is in active state or in background while receiving remote notification using didReceiveRemoteNotification method.
A simple solution I can think of is to make use of applicationDidBecomeActive: and applicationDidEnterBackground:. Declare a property in your app delegate and set it properly in those two methods. Then you can do anything you want based on this property, like [[[UIApplication sharedApplication] delegate] isInBackground].