热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS平台下MQTT协议在弹幕功能中性能优化的探讨与实践

由于没有做数据过滤,所以App会收到大量数据,造成app 页面卡死,数据大概每秒300个数据左右,现在感觉下来的数据用ObjectMapper 转model 消耗很大,还有就是我去操作tableVie

由于没有做数据过滤,所以App会收到大量数据,造成app 页面卡死,数据大概每秒300个数据左右,现在感觉下来的数据用ObjectMapper 转model 消耗很大,还有就是我去操作tableView的时候也很大,所以请大家给提些建议优化下,感谢!!!
代码如下:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    //处理服务端返回的弹幕消息

    func handleMessage(_ data: Data!) {

        let json = JSON(data)

        if json["userName"].string != nil && json["message"].string != nil {



                if let d = json.dictionaryObject {

                    if let entity = Mapper().map(JSON: d) {

                        self.tableView?.addNewDanmu(entity)

                        self.danmu_List.append(entity)

       

                    }

                }

        }

    }

   

   

   

   

     func addNewDanmu(_ danmu: [DTDanmuMessageEntity])  {

       

        self.danmu += danmu

        let indexPath = NSIndexPath(row: self.danmu.count - 1, section: 0)

         self.beginUpdates()

        self.insertRows(at: [indexPath as IndexPath], with: .bottom)

        self.endUpdates()

       



       

        if self.contentSize.height
            return

        }

        //滚动到最底部

        self.scrollToRow(at: indexPath as IndexPath, at: .bottom, animated: true)

       

     

     

        }



   



推荐阅读
author-avatar
mobiledu2502912277
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有