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

时间:2015-03-30 17:25:34

标签: ios objective-c xcode apple-push-notifications

我刚在我的应用中实现了评论功能。理想情况下,当有人发表评论时,我希望所有通知的人都可以刷推推送通知并在该帖子上打开应用。

1 个答案:

答案 0 :(得分:1)

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

如果要在应用启动时打开内部页面,可以通过编程方式触发用户需要手动创建的segue。 (这确保后退/主页按钮工作,而不是直接加载所需页面)。 这是我自己的一个代码的摘录,你的用例可能不一样,但除非你给我们更多细节,否则这就是我所能做的。

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

我希望代码是自我解释的。欢呼声