繁体   English   中英

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

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

我有一个应用程序,当该应用程序处于非活动状态并且我的代码是这样时,我正在发送解析规范? 在我的

AppDelegate.m

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

但是我需要转到此通知的特定页面:例如,我需要在触发推送通知时打开MUSICViewController。 如何从应用程序委托转到该屏幕; 另一个重要的事情是,如果未启动该应用程序,我将如何启动该应用程序并处理通知。 有关信息,应在应用程序启动之前从服务器获取一些数据。 请帮忙怎么处理?

如果您使用情节提要

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

其他

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

比现在这个新的VC

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

如果[[app keyWindow] rootViewController]是导航控制器

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

我正在共享我的应用程序代码,您可能会从中得到一些想法

- (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