0

I've an app and I am sending the parse norifications when the app is inActive and my code is like this? in my

AppDelegate.m

-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if([app applicationState] == UIApplicationStateInactive)
    {
        //Here I've written
       [PFPUSH handlePush:UserInfo];
    }
}

But I need to go to a perticular page on this notification: For example I need to open my MUSICViewController on triggering the push notification. How to go that screen from app delegate; And another important thing is if the app is not launched, How I've to launch the app and handle the notification. And for info some data is to be get from server before the app launches. Please help how to handle it?

Jack
  • 81
  • 2
  • 9

2 Answers2

0

if you use storyboards

UIViewController *controller = [[[[app keyWindow] rootViewController] storyboard] instantiateViewControllerWithIdentifier:@"MUSICViewController"];

else

MUSICViewController *viewController = [[MUSICViewController alloc] init];

than present this new VC

[[[app keyWindow] rootViewController] presentViewController:viewController
                                                           animated:YES
                                                         completion:nil];

if [[app keyWindow] rootViewController] is Navigation controller

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *nav = [[app keyWindow] rootViewController];
[nav pushViewController:nav animated:YES];
Moonkid
  • 881
  • 7
  • 17
0

i am sharing my application code might you get some idea from that

- (void)applicationDidReceiveRemoteNotification:(NSDictionary *)userInfo fromState:(UIApplicationState)state
{

if ([UIApplication userId]) {

    if (state == UIApplicationStateActive)
    {
        [[PPAlerts sharedAlerts]showAlertWithType:AlertTypeToast withMessage:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]];
        //[PFPush handlePush:userInfo];
    }


    if (!IS_IPHONE_SIMULATOR)
    {
        if ([UIApplication userId])
        {
            PFInstallation *currentInstallation = [PFInstallation currentInstallation];
            if (currentInstallation.badge >= 1)
            {
                long k = currentInstallation.badge-1;
                [[UIApplication sharedApplication] setApplicationIconBadgeNumber:k];
                currentInstallation.badge = k;
                [currentInstallation saveInBackground];
            }
        }
    }

    if ([[userInfo objectForKey:@"t"] isEqualToString:@"request"] || [[userInfo objectForKey:@"t"] isEqualToString:@"t"]) {
        self.isRequest = true;
    }
    else
    {
    self.isRequest = false;
    }

    NSLog(@"1-->user");
    if ([UIApplication userId] && [[UIApplication sharedApplication] applicationState] != UIApplicationStateActive)
    {
        NSLog(@"2-->inactive");
        if (self.sidePanelViewController==nil) {
            NSLog(@"3-->forcestop");
            LoginViewController *login= [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
            self.isNotifiction=true;

            self.notificationID = [userInfo numberForJson:@"id"];

            [self openMenuViewcontroller:login];
        }
        else
        {
            NSLog(@"4-->runnigBG");
            if (self.isRequest) {
                self.tabBarController.selectedIndex = 4;

            }
            else
            {
            NotificationViewController *notif=[[NotificationViewController alloc]initWithNibName:@"NotificationViewController" bundle:nil];
            notif.isParseNotifiction=true;
            self.notificationID = [userInfo numberForJson:@"id"];
            SuperNavigationController *navNoti = [[SuperNavigationController alloc]initWithRootViewController:notif];
            self.sidePanelViewController.centerPanel = navNoti;
            }
        }
    }
    else
    {
      //  [[APIRequest request]HomeCount:@"0" completed:nil];
        if (appDelegate.isLogin) {
        [[APIRequest request]NotifictionCount:@"0" completed:nil];
        [[APIRequest request]invitationCount:@"0" completed:nil];
        [[APIRequest request]whislistCount:@"0" completed:nil];
        }
        NSLog(@"5-->active");
        if(self.isRequest)
        {
            self.isRequest = false;
            if (self.isRequestOpen) {
                [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
                [[PFInstallation currentInstallation] setBadge:0];
                [[PFInstallation currentInstallation] saveEventually];
            }

        }
        else if (appDelegate.isNotifiction)
        {
            [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
            [[PFInstallation currentInstallation] setBadge:0];
            [[PFInstallation currentInstallation] saveEventually];
            [[APIRequest request]NotifictionAll:appDelegate.UserID ShowLoader:NO completed:nil];
        }
        else
        {

        }
    }

}

}
Leo
  • 24,596
  • 11
  • 71
  • 92
Jaydeep Patel
  • 1,699
  • 17
  • 30
  • Hey Thnaks but cant understand your code. In app delegate method in didrecieveRemoteNotiicationMethod, if app is in background. what should i do, please write that much only... – Jack Dec 23 '15 at 07:36
  • your application is in background then ` if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive)` write your code to open MUSICViewController in this condition – Jaydeep Patel Dec 23 '15 at 07:43