• iOS开发 落地消息多的处理办法(仅供参考)


    1.首先要知道一点,你的消息储存是用数据库储存的!

    看了一下微信和qq的消息处理,一般情况下第三方(亲加,容云,环信都会有本地的数据库)处理过的!

    但是我发现,最近一个需求要求开发@”消息已读“@”消息送达“的处理,和UI显示。

    我想了各种办法,GCD线程异步,带来的会有另外的一个问题,多线程访问同一个资源,be locked。或者说你在接收到消息的时候开一个线程,接到消息的时候开一个线程。一般情况下是没有问题的。但是重新一个账号登陆的时候就会有以前你读过和没有读过的消息!(如果你们购买了,app和网页消息同步的时候)!

    解决办法:

    后台开一个永驻线程(有崩溃主线程中也不受到影响),而且也不会多个线程访问同一个路径下的数据库

    @property (nonatomic, strong) NSThread *thread;

    /***开启一个永驻线程**/

    - (void)threadRunloopPoint:(id)__unused object{

        NSLog(@"%@",NSStringFromSelector(_cmd));

        @autoreleasepool {

            [[NSThread currentThread] setName:@"changzhuThread"];

            NSRunLoop *runLoop = [NSRunLoop currentRunLoop];

            //// 这里主要是监听某个 port,目的是让这个 Thread 不会回收

            [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];

            [runLoop run];

        }

    }

    - (NSThread *)thread{

        if(!_thread){

            _thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadRunloopPoint:) object:nil];

            [_thread start];

        }

        return _thread;

        

    }

    //接收到已读消息回执的代理

    - (void)NotificationCenterReadMessage:(NSNotification *)notification{

        ReadMessageTime * readMark = [[ReadMessageTime alloc]init];//已读回执消息对象(自己建立)

        readMark.cType = [notification.userInfo objectForKey:@"cType"];

        readMark.messageTime = [notification.userInfo objectForKey:@"messageTime"];

        readMark.tId = [notification.userInfo objectForKey:@"tId"];

        [self performSelector:@selector(insertReadMessageTime:) onThread:self.thread withObject:readMark waitUntilDone:NO modes:@[NSDefaultRunLoopMode]];

    }

    - (void)insertReadMessageTime:(id)readMark{

        [[[MyFMDB alloc]init] insertReadMessageTime:readMark];

    }

  • 相关阅读:
    is running beyond physical memory limits. Current usage: 2.0 GB of 2 GB physical memory used; 2.6 GB of 40 GB virtual memory used
    saiku执行速度优化二
    saiku执行速度慢
    saiku 升级&备份&恢复
    saiku 展示优化第二步(要诀和技巧)
    saiku 无密码登陆
    saiku 展示优化
    saiku源代码安装
    结合使用saiku、mondrian workbentch建立多维查询报表
    浅析 mondrian 模式文件 Schema
  • 原文地址:https://www.cnblogs.com/PeterWolf/p/6114291.html
Copyright © 2020-2023  润新知