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

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

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

最佳答案

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

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

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

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

关于ios - APNS打开应用程序的某个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29352439/

相关文章:

Objective-C——同一个库的不同版本导致名称冲突

XCode 使用 ncurses 构建命令行工具

ios - 如何在 Swift 中将 UITableView 的单元格文本设置为数据库单元格的内容?

ios - 是否可以在呈现屏幕的层次结构中的特定元素处呈现 UIViewController 以符合 Google Admob 政策?

ios - 如何防止两次执行相同的segue?

objective-c - 使用 Objective-C @encode 检查任意 C 类型的相等性——已经存在了吗?

ios - Google maps turn by turn 用于 ios 开发的 gps 导航

ios - 如何在 Swift 中更改滑动操作的 UITableviewCell 背景颜色?

iphone - 检查绘制的路径/CGPath 是否在 iPhone 游戏中与自身相交

ios - 更新设备旋转变化时的阴影路径。阴影问题