zoukankan      html  css  js  c++  java
  • 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];
    }
  • 相关阅读:

    tomcat 和jboss区别
    python好文章
    CUBRID学习笔记 34 net参数化查询 cubrid教程示例
    CUBRID学习笔记 33 net事务 cubrid教程示例
    CUBRID学习笔记 32 对net的datatable的支持 cubrid教程
    CUBRID学习笔记 31 通过select创建表
    CUBRID学习笔记 30 复制表结构 cubrid教程
    CUBRID学习笔记 29 web管理中文语言文件 CUBRID教程
    CUBRID学习笔记 28 执行sql脚本文件
  • 原文地址:https://www.cnblogs.com/code-changeworld/p/4769830.html
Copyright © 2011-2022 走看看