Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open another screen instead of Main Screen when push notification received

I need to know how to open another viewcontroller instead of the main view controller when the push notification received please help me thanks in advance here is my code"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    sleep(2);
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
 (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
    consumerId = [[ud objectForKey:@"consumerId"] intValue];

    couponSql = [[CouponsSqlClass alloc] init];

   if (consumerId == 0) {
        self.viewController = [[LandingPageViewController alloc] initWithNibName:@"LandingPageViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
   }
   else {
        application.applicationIconBadgeNumber = 0;

        EditProfileViewController* mainViewController = [[EditProfileViewController alloc] initWithNibName:@"EditProfileViewController" bundle:nil];
        _mainViewNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
        KluebookMenuViewController* leftSideMenuViewController = [[KluebookMenuViewController alloc] initWithNibName:@"KluebookMenuViewController" bundle:nil];
        self.deskController = [[IIViewDeckController alloc] initWithCenterViewController:self.mainViewNavController leftViewController:leftSideMenuViewController];
        self.deskController.leftLedge = 60;
        self.window.rootViewController = self.deskController;
    }
    [self.window makeKeyAndVisible];

    return YES;
}
like image 704
Vishnu Avatar asked Aug 05 '13 10:08

Vishnu


People also ask

What is the difference between local notification and push notification?

The essential difference between local notifications and push notifications is simple: Local notifications are scheduled by an app locally and are delivered by the same device. Push notifications are sent by a remote server (its provider) which sends these notifications to devices on which the app is installed.

How do I handle background notifications on Android?

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console).


1 Answers

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
         //Redirect it to your page here
    }
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground  )
    {
         //opened from a push notification when the app was on background
         //Redirect it to your page here
    }
}
like image 126
Baby Groot Avatar answered Oct 22 '22 08:10

Baby Groot