IOS推送消息处理跳转指定页面

APP有UITabbarController、UINavigationController;

主页:FirstViewController

指定页:MyViewController

@interfaceCustomTabBarViewCtr:UITabBarController

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="color: rgb(222, 56, 166);">@interface</span><span style="color:#009900;"> CustomNavigationViewCtr : </span><span style="color:#3333ff;">UINavigationController</span></p>

后台运行时:

<pre name="code" class="objc"><span style="color:#006600;">// ios7 later 点击推送消息 调用此方法
</span><span style="color:#3333ff;">
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    application.applicationIconBadgeNumber = 0;

    [self getCurrentRootViewController:application];

    completionHandler(UIBackgroundFetchResultNoData);
}</span>

 

<pre name="code" class="objc"><pre name="code" class="objc"><span style="color:#006600;">//    获取当前viewcontroller</span>
<span style="color:#3333ff;">-(void)getCurrentRootViewController:(UIApplication*)applocation
{
    CustomTabBarViewCtr * instance = [CustomTabBarViewCtr shareTabBarViewCtr];
    UIViewController *controller = instance.selectedViewController;
    
    if ([controller isKindOfClass:[UINavigationController class]]){
        
        controller = [(UINavigationController *)controller visibleViewController];
        
        MyMesgesViewController *five=[[MyMesgesViewController alloc]init];

        [controller.navigationController pushViewController:five animated:YES];
    
    }
}</span>
 
 


程序关闭时:
 <pre name="code" class="objc"><span style="color:#009900;">//程序在关闭状态时  点击推送消息打开程序则 launchOptions 不为空</span>  
<span style="color:#3333ff;">-(void)zhuceTuiSOng:(UIApplication *)application WithOptions:(NSDictionary *)launchOptions
{
   ......其他代码......

    if (launchOptions) {
        application.applicationIconBadgeNumber = 0;
        /* 想处理的代码写在这 */
        //截取apns推送的消息
        NSDictionary* pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
        //获取推送详情
        NSString *pushInfostr = [NSString stringWithFormat:@"%@",[pushInfo  objectForKey:@"aps"]];

    }
}</span>
<span style="color:#009900;">会自动调用方法- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;</span>

 
</pre><br /><br /><p><br /></p><p>// 附属方法,这是一些其他类里的方法,为了方便理解上边代码,单独拷贝出来以供参考理解</p><p></p><pre name="code" class="objc"><span style="color:#3333ff;">+(CustomTabBarViewCtr *)shareTabBarViewCtr
{
    static CustomTabBarViewCtr * instance = nil;
    if (instance == nil) {
        instance = [[CustomTabBarViewCtr alloc] init];
    }
    return instance;
}
</span>
<span style="color:#3333ff;">-(void)addViewCtrs
{
    FirstViewController * fvc = [[FirstViewController alloc] init];
    CustomNavigationViewCtr * cvc1 = [[CustomNavigationViewCtr alloc] initWithRootViewController:fvc];
    
    SecondViewController * fvc2 = [[SecondViewController alloc] init];
    CustomNavigationViewCtr * cvc2 = [[CustomNavigationViewCtr alloc] initWithRootViewController:fvc2];
    
    NSArray * aryTemp = [NSArray arrayWithObjects:cvc1,cvc2, nil];
    
    
    self.viewControllers = aryTemp;
}</span>


评论是一种美德,是对作者的一种鼓励,欢迎斧正,谢谢!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值