简体   繁体   English

如何在iOS目标C中处理解析通知?

[英]How to handle parse Notification in ios objective c?

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. 但是我需要转到此通知的特定页面:例如,我需要在触发推送通知时打开MUSICViewController。 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? 请帮忙怎么处理?

if you use storyboards 如果您使用情节提要

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

else 其他

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

than present this new VC 比现在这个新的VC

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

if [[app keyWindow] rootViewController] is Navigation controller 如果[[app keyWindow] rootViewController]是导航控制器

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *nav = [[app keyWindow] rootViewController];
[nav pushViewController:nav animated:YES];

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
        {

        }
    }

}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM