• iOS本地通知


    今天项目中用到了消息推送第一次做这方方面的内容先记录下来。

    这个项目采用的时第三方的极光推送按照极光的文档配置好后,

    当有推送时会在以下方法中收到服务器的推送通知,以及推送消息内容。

    - (void)networkDidReceiveMessage:(NSNotification *)notification {
        NSDictionary *userInfo = [notification userInfo];
        NSDictionary *extras = userInfo[@"extras"];
        NSString     *type = extras[@"type"];
        //NSString *content = [userInfo valueForKey:@"content"];
            [self handleRemoteNotification:userInfo];//获得推送内容,调用处理推送的方法
    }

    处理推送要判断App当前的状态

    - (void)handleRemoteNotification:(NSDictionary *)userInfo{
        if(userInfo[@"_j_msgid"] || userInfo[@"content"]){
            UIApplicationState state=[UIApplication sharedApplication].applicationState;
            if(state==UIApplicationStateActive || state==UIApplicationStateInactive){//在前台
                [[NSNotificationCenter defaultCenter]postNotificationName:r7_fetchRemoteNotificationNotify object:nil userInfo:userInfo];
                SuperNavigationController  *navCtrl = (SuperNavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                SuperTabController *tabCtrl=(SuperTabController*)navCtrl.rootViewController;
                
                [tabCtrl dealWithPushInfo:userInfo applicationState:state];
                
                if(state==UIApplicationStateInactive){
                    [APService setBadge:0];
                    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];
                }
            }
            else if(state==UIApplicationStateBackground){//通知推送至后台
                _userInfo=userInfo;
                [self addLocationRemind];
            }
            [APService handleRemoteNotification:userInfo];
            DLog(@"userInfo:%@",userInfo);
        }
    
    }
    - (void)addLocationRemind {
        GlobalSingle *single =  [GlobalSingle sharedSingleInstace];
        NSInteger discussDynamicNumber = [single numberToIntWithKey:DYNAMICNUMBERKEY] + 1;
        [single saveNumberWith:discussDynamicNumber key:DYNAMICNUMBERKEY];
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5];
        UILocalNotification *note = [[UILocalNotification alloc] init];
        note.alertBody = @"来自NEUQer的提醒";
        note.alertAction = @"回复";
    //    note.alertLaunchImage = @"discuss_selected";
        note.applicationIconBadgeNumber = 1;
        note.soundName = UILocalNotificationDefaultSoundName;
        note.fireDate = date;
        [[UIApplication sharedApplication] scheduleLocalNotification:note];
    }
  • 相关阅读:
    大数据架构师技能图谱
    2018年,Java程序员转型大数据开发,是不是一个好选择?
    如何将java web项目上线/部署到公网
    Flume调优
    Spark流处理调优步骤
    zookeeper的WEB客户端zkui使用
    HBase各版本对Hadoop版本的支持情况
    java 代码实现使用Druid 链接池获取数据库链接
    安装postgreSQL出现configure: error: zlib library not found解决方法
    修改postgres密码
  • 原文地址:https://www.cnblogs.com/code-changeworld/p/4769830.html
Copyright © 2020-2023  润新知