APNS打开应用程序的某个部分

APNS to open a certain part of an application

我刚刚在我的应用程序中实现了评论功能。理想情况下,当有人发表评论时,我希望所有收到通知的人都能够滑动推送通知并打开 post.

上的应用程序

我假设你想直接打开相关页面。有很多方法可以解决这个问题,这取决于您的应用程序的布局方式。

如果您想在应用程序启动时打开内页,您可以通过编程方式触发用户否则需要手动进行的转场。 (这确保 back/home 按钮可以正常工作,而不是直接加载所需的页面)。 这是我自己的一段代码的摘录,您的用例可能不一样,但这就是我所能做的,除非您提供更多详细信息。

- (BOOL) navigateToRespectiveSectionforPushNot:(NSDictionary*)pushNot
{
 id rootVC = self.window.rootViewController;

 NSLog(@"ROOT CLASS : %@", [rootVC class]);
 if ([rootVC isKindOfClass:[SWRevealViewController class]])
 {
   NSLog(@"Root Class looking good... mission Navigate!!");
   SWRevealViewController *homeVC = (SWRevealViewController*) rootVC;

    NSString *category = [[pushNot objectForKey:pushPayloadKeyaps] objectForKey:pushPayloadKeyCategory];
    NSString *subCat = [[pushNot objectForKey:pushPayloadKeyaps] objectForKey:pushPayloadKeySubCategory];
    NSLog(@"category : %@ , subcat : %@",category,subCat);
    //The code for the page to which i'm supposed to navigate to is contained in the push notification payload

    if ([category isEqualToString:pushCategoryItemChat])
    {
        [homeVC.rearViewController performSegueWithIdentifier:@"chatPush" sender:nil];
        UINavigationController *nc = (UINavigationController*)homeVC.frontViewController;
        NSLog(@"FrontView Class : %@",[nc.viewControllers[0] class]);
        UITableViewController *tvc = (UITableViewController*)nc.viewControllers[0];
        NSDictionary *send = @{chatPushTargetUserId:subCat,chatPushTargetUserName:@"",chatPushTargetUserImage:@""};
        [tvc performSegueWithIdentifier:@"seguePushDemoVC" sender:send];
        return YES;
    }
    //communityPush historyPush
    else if ([category isEqualToString:pushCategoryItemCommunity])
    {
        if ([subCat isEqualToString:pushSubCatItemNewRequest])
        {
            [homeVC.rearViewController performSegueWithIdentifier:@"communityPush" sender:nil];
            return YES;
        }
        else if ([subCat isEqualToString:pushSubCatItemAccepted])
        {
            [homeVC.rearViewController performSegueWithIdentifier:@"communityPush" sender:nil];
            return YES;
        }
    }
    else if ([category isEqualToString:pushCategoryItemHistory])
    {
        [homeVC.rearViewController performSegueWithIdentifier:@"historyPush" sender:nil];
        return YES;
    }
 }
 else
 {
    UIAlertView *whoa = [[UIAlertView alloc] initWithTitle:@"WHOA!!" message:@" That wasn't supposed to happen. You are not even logged in. Call 911..." delegate:nil cancelButtonTitle:@"mmKay.." otherButtonTitles:nil, nil];
    [whoa show];
 }
 return NO;
}

我希望代码是不言自明的。干杯