when application become active then how we load the another view or invoke the root view controller - iphone

i have load the mailcomposer on reciving the localnotification
is it possible??

You should code as follows,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
//code for opening mail composer
}
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//code for opening mail composer
}

Related

How to get notification.alertBody in my app from a remote push notification?

I just followed this tutorial Push notification and I successfully implemented the push notification for my iPhone app. Im able to get now the notification Details. However, I wanted to put the notification alertBody on a Label provided for notification alertBody.
I have a code in displaying the notification alertBody from a local Notification. But I know it is different from a push notification because it is used only for local notification.
on my AppDelagate.m
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSLog(#"Recieved Notification %#",notif);
NSString *_stringFromNotification = notif.alertBody;
[[NSNotificationCenter defaultCenter] postNotificationName:#"Notification" object:_stringFromNotification];
}
on my ViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:#"Notification" object:nil queue:nil usingBlock:^(NSNotification *note)
NSString *_string = note.object;
//Do something with the string--------
}];
}
It works perfectly on Local Notification but for push notification, It doesn't work. How to Implement this? Need your help please. I need to put the notification alert body at the Label or String.
first of all register for remote notifications in AppDelegate.m in method,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Invoke APNS.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
And then use following delegate method to recieve remote notification:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"Received =%#",userInfo);////userInfo will contain all the details of notification like alert body.
}
Remote notifications run outside the sandbox the app is running in, so you can't capture the notification in the same way as local notifications, i.e. application:didReceiveLocalNotification. However, if the app is launched via the remote notification, you can capture the notification via the application:didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
// do something with the notification.alertBody
} else {
// from the springboard
}
}
If your application is already running when it receives a remote notification, your application delegate's – application:didReceiveRemoteNotification: method will be called; if the application is not currently running and is launched in response to the notification, the remote notification info will be put into the launchOptions dictionary in your – application:didFinishLaunchingWithOptions: method.
The method which you are implementing is for local notification only. If you want to handle push notification then you have to use method
- (void)application:(UIApplication*)application didReceiveRemoteNotification: (NSDictionary*)userInfo{
NSLog(#"Received notification: %#", userInfo);
}
for the same. This method will be called if the app is on background only. If the app is not in background then you can fetch data in the following manner
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UILocalNotification *notificationData = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if(!notificationData){
NSLog(#"App launched by tapping on app icon");
}else{
NSLog(#"Notification data -> %#",notificationData);
}
}

localNotification issues

I am sending a local notification once a process is finished and it acts just fine.
This is my code for didReceiveLocalNotification:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
CounterViewController *counterVC = [CounterViewController sharedInstance];
[counterVC notificationArrived];
}
But when the iPhone is locked those lines aren't called… What can I do to make them run in the background?
There are two method to receive local notification one is already you have implemented which is invoked while app is running & 2nd is in didFinishLaunchingWithOptions which is invoked while your app is running background you have add some code for receive local notification .....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
return YES;
}

Current tab from storyboard

If I create a Tab Bar Application project template with storybard and put this in my AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"Root: %#", self.window.rootViewController);
NSLog(#"Current ViewController: %#", /*self.window.rootViewController.selectedIndexOrSomething?*/ );
return YES;
}
It says: Root: <UITabBarController: 0x6b20360>
So I guess the TabBarController is already added as a subView of the window property as I have not touched the AppDelegate in any other way than NSLog.
How to log the current tab/ViewController?
You will want to do this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"Root: %#", self.window.rootViewController);
NSLog(#"Current ViewController: %#", ((UITabBarController *)self.window.rootViewController).selectedViewController );
return YES;
}

Push Notifications on iPhone App

I have successfully implemented push notifications to my app. The next step is, if the user receives a notification about this certain document, he/ she clicks it and it brings them to this document.
At the moment, I can receive the notification, but it only brings me to the app.
How can I do this?
Thanks.
I am not clear with your question. But you should handle push notifications in the following methods,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//Handle here
}
and
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *tmpDic = [launchOptions objectForKey:#"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (tmpDic != nil) {
//Handle here also
}
}

error lauchoptions undeclared IOS4?

application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
return YES;
i am getting lauchoptions undeclared my os veriosn is 4 and xcode i 3.2.3
Well, where are you getting the variable "launchOptions" from? Presumably, you're using
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Did you rename the argument? Perhaps you need to show more of your code...