• iOS刚进入后台接受推送、打开推送调转到相应的界面


    刚进入后台的时候消息处理时候我用了本地推送!可以看我前边写的博客,怎么处理刚进入后台接收推送的案例,链接

    /**

     注释:打开推送的三种方式:-peter

     1、apns的时候,结束进程退出后台:启动的时候可在 didFinishLaunchingWithOptions的launchOptions中处理;

    获取字典 launchOptions 中的 UIApplicationLaunchOptionsRemoteNotificationKey的key

       NSDictionary *optionsRemoteNotificationKey = [launchOptions dictionaryValueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    {

        /**二次启动获得推送点击信息,本地储存二次启动的内容 仿qq点击推送栏启动 by peter***/

       NSDictionary *optionsRemoteNotificationKey = [launchOptions dictionaryValueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

        [[NSUserDefaults standardUserDefaults] setObject:optionsRemoteNotificationKey forKey:kSavePushMessage];

        /**为了验证第一次启动的时候不能截获启动信息,加啊alert**/

        /**

        NSString * str = [NSString stringWithFormat:@"%@",launchOptions];

     

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            UIAlertView *art = [[UIAlertView alloc]initWithTitle:nil message:str delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];

            [art show];

     

        });

        **/

        return YES;

    }

     2、apns的时候,结束进程未退出后台:启动的时候可在 didReceiveRemoteNotification的userInfo中处理;

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    {

        NSString *  appData = [userInfo stringValueForKey:@"appData"];

        

        NSData *jsonData = [appData dataUsingEncoding:NSUTF8StringEncoding];

        NSError *err;

        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData

                                                            options:NSJSONReadingMutableContainers

                                                              error:&err];

        

        if(err)

        {

            NSLog(@"json解析失败:%@",err);

        }else{

            NSString * positionIdString = [NSString stringWithFormat:@"%@",[dic numberValueForKey:@"positionId"]] ;

            if ([dic numberValueForKey:@"positionId"] !=0) {

                [[NSNotificationCenter defaultCenter] postNotificationName:kString_DispantData object:positionIdString];

            }

        }

    }

     3、本地推送,未结束进程未退出后台(此方达为了解决消息刚进入后台时候没有通知的情况):启动的时候可在 didReceiveLocalNotification的notification中处理;

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

        NSDictionary *dic = notification.userInfo;

        NSString * positionIdString = [dic stringValueForKey:@"positionId"];

        if (![positionIdString isEqualToString:@""]) {

            [[NSNotificationCenter defaultCenter] postNotificationName:kString_DispantData object:positionIdString];

        }

     

    }

     **/

    二、处理页面跳转功能

    说明:由于情况1都代表app已经结束需要重新启动,只能做本地存储,然后到tabbar页面的时候取出该存储值的对应id然后进行跳转。情况2、3  ,App的tabbar页面已经存在可以注册一个通知在2、3的情况时候发送通知!

    1、存储调转

    在tabbar的viewDidAppear方法

    - (void)viewDidAppear:(BOOL)animated

    {

        [super viewDidAppear:animated];

        

        NSDictionary *optionsRemoteNotificationKey = [[NSUserDefaults standardUserDefaults] objectForKey:kSavePushMessage];

        NSString *appDataString = [optionsRemoteNotificationKey stringValueForKey:@"appData"];

        if (appDataString&&![appDataString isEqualToString:@""]) {

            [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kSavePushMessage];

        }

    }

    2、通知跳转

    注册监听tabbar的viewDidLoad方法里边

    - (void)viewDidLoad

    {

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushDispanchPositionDetail:) name:kString_DispantData object:nil];

    }

     方法接收

    #pragma mark observer Notification

    -(void)pushDispanchPositionDetail:(NSNotification *)notify

    {

        if (notify.object&&![notify.object isEqualToString:@""]) {

            [self pushData:notify.object];

        }

    }

     

    - (void)pushData:(NSString *)positionId{

        [self setSelectedIndex:MainTabBarIndex_User];

        RootNavigationController* selNavi = [self.viewControllers objectAtIndex:MainTabBarIndex_User];

        HHPositionDetailC *vc = [[HHPositionDetailC alloc] init];

        vc.positionId = [positionId longLongValue];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            selNavi.toolbar.hidden = YES;

            [selNavi pushViewController:vc animated:YES];

            HDMyPositionViewController *myPositionVC = [[HDMyPositionViewController alloc]init];

            NSMutableArray *mutArray = [NSMutableArray arrayWithArray:selNavi.viewControllers];

            [mutArray insertObject:myPositionVC atIndex:1];

            selNavi.viewControllers = [mutArray copy];

        });

    }

    详细解释跳转代码

        [self setSelectedIndex:MainTabBarIndex_User];

        RootNavigationController* selNavi = [self.viewControllers objectAtIndex:MainTabBarIndex_User];

        HHPositionDetailC *vc = [[HHPositionDetailC alloc] init];

        vc.positionId = [positionId longLongValue];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            selNavi.toolbar.hidden = YES;

            [selNavi pushViewController:vc animated:YES];

            HDMyPositionViewController *myPositionVC = [[HDMyPositionViewController alloc]init];

            NSMutableArray *mutArray = [NSMutableArray arrayWithArray:selNavi.viewControllers];

            [mutArray insertObject:myPositionVC atIndex:1];

            selNavi.viewControllers = [mutArray copy];

        });

    1、找到所进入的viewController的根导航Navigation;然后进行选中(self代表tabbar)  [self setSelectedIndex:MainTabBarIndex_User];

    2、然后延迟调转,由于初始化tababr的原因不延迟跳转会出现调转不进去的情况;所以做延迟跳转处理。

       [selNavi pushViewController:vc animated:YES];

    3、找到当前的viewControllers数组,创建需要返回的二级页面加入栈中!

    这样就能点推送进入C,返回B,在返回所需要的tabbar的某个界面。

  • 相关阅读:
    由Kaggle竞赛wiki文章流量预测引发的pandas内存优化过程分享
    Python奇技淫巧 持续更新中....
    波士顿房价预测 最简单入门机器学习 Jupyter
    机器学习基本流程整理 这一篇就够啦
    阅读kaggle上大佬们的kernel
    wechat+项目开源分享 让你的微信账号有趣起来
    ✍36 PyQt5 模块错误排除
    ✍41 搭建wordpress&花生壳穿透
    ✍44.vs code远程编辑代码
    ✍42.图片识别相关cv2
  • 原文地址:https://www.cnblogs.com/PeterWolf/p/7886342.html
Copyright © 2020-2023  润新知