专栏首页移动端周边技术扩展早期 iCome iOS客户端设计

早期 iCome iOS客户端设计

简书部分流程图看不到,可移步

应用启动的主要流程

st=>start: AppDelegate
islogin=>condition: isLogin?
login=>operation: http登录
tcp=>operation: tcp注册登录
newdesc=>operation: 功能引导
rootVC=>operation: 主控制器
mainVC=>operation: 主页
sync=>operation: 数据同步

e=>end



st->islogin
islogin(yes)->tcp->rootVC->e
islogin(no)->newdesc->login(left)->tcp->rootVC->mainVC->sync->e

1. 整体架构与模块化划分设计

项目采用Category方式设计把项目按照某个具体业务逻辑功能划分、采用中间调度模块IComMediator管理输入与回调内容进行模块化解耦

#import <Foundation/Foundation.h>
typedef void (^IComMediatorObjectHandler)(id result);
@interface IComMediator : NSObject
+(instancetype)sharedInstance;
// 远程App调用入口
- (id)performActionWithUrl:(NSURL *)url completion:(void(^)(NSDictionary *info))completion;

// 本地组件调用入口
- (id)performTarget:(NSString *)targetName action:(NSString *)actionName params:(NSDictionary *)params;

// 充分模块化解耦 存储block用页面跳转调用
- (id)performTarget:(NSString *)targetName action:(NSString *)actionName params:(NSDictionary *)params completion:(IComMediatorObjectHandler)completion;
// 所有b页面回调
- (void)toHandlerTargetName:(NSString *)targetName action:(NSString *)actionName param:(id)param;

@end

项目功能模块

384CB19E-4141-47C3-8AB5-D93DA9A509DC.png


项目文件结构

项目文件结构.png

每一个模块文件结构相同,模块中的Actions与Category 负责本模块的功能被调度

项目文件结构展开.png

    #import "IComMediator+DynamicModuleActions.h"
    // action 类名 Dynamic 模块统一用Dynamic 模块名
    NSString * const kIComMediatorTargetDynamic = @"Dynamic";
    // 类对应方法名 一个模块下不同控制器的类名
    NSString * const kIComNativeFetchDynamicViewController = @"nativeFetchDynamicViewController";
    NSString * const kIComNativeFetchDiscoverViewController = @"nativeFetchDiscoverViewController";
    //DiscoverViewController

    @implementation IComMediator (DynamicModuleActions)
    - (UIViewController *)IComMediator_DynamicViewController:(NSDictionary *)params {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetDynamic
                                                    action:kIComNativeFetchDynamicViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        // view controller 交付出去之后,可以由外界选择是push还是present
        return viewController;
    } else {
        // 这里处理异常场景,具体如何处理取决于产品
        return [[UIViewController alloc] init];
    }
    }

- (UIViewController *)IComMediator_DiscoverViewController:    (NSDictionary *)params
    {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetDynamic
                                                    action:kIComNativeFetchDiscoverViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {

        return viewController;
    } else {
        return [[UIViewController alloc] init];
    }
    }
    @end

公共部分负责项目每个模块的整体调度与协作

负责公共部分.png

每个模块的Category调度器均为主调度器(IComMediator)的Category

IComMediator.h

#import <Foundation/Foundation.h>

@interface IComMediator : NSObject

+(instancetype)sharedInstance;

// 远程App调用入口
- (id)performActionWithUrl:(NSURL *)url completion:(void(^)(NSDictionary *info))completion;

// 本地组件调用入口
- (id)performTarget:(NSString *)targetName action:(NSString *)actionName params:(NSDictionary *)params;

@end

IComMediator.m

    #import "IComMediator.h"
    #import "NSDictionary+URL.h"

    @implementation IComMediator
    +(instancetype)sharedInstance {
    static IComMediator *mediator;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        mediator = [[IComMediator alloc] init];
    });
    return mediator;
    }

    // 远程App调用入口
    - (id)performActionWithUrl:(NSURL *)url completion:(void(^)(NSDictionary *info))completion {
    if (![url.scheme isEqualToString:@"icom"]) { // 外部启动规则
        // 这里就是针对远程app调用404的简单处理了
        return @(NO);
        }

    NSDictionary *params = [NSDictionary dictionaryWithURLQuery:[url query]];
    
    NSString *actionName =
    [url.path stringByReplacingOccurrencesOfString:@"/" withString:@""];
    
    id result = [self performTarget:url.host action:actionName params:params];
    if (completion) {
        if (result) {
            completion(@{ @"result" : result });
        } else {
            completion(nil);
        }
    }
    return result;
    }

    // 本地组件调用入口
    - (id)performTarget:(NSString *)targetName action:(NSString *)actionName params:(NSDictionary *)params {
    // 运行时方式 让对应的目标类执行对应的目标方法
    NSString *targetClassString =
    [NSString stringWithFormat:@"Target_%@", targetName];
    NSString *actionString =
    [NSString stringWithFormat:@"Action_%@:", actionName];
    
    Class targetClass = NSClassFromString(targetClassString);
    id target = [[targetClass alloc] init];
    SEL action = NSSelectorFromString(actionString);
    
    if (target == nil) {
        // 这里是处理无响应请求的地方之一,这个demo做得比较简单,如果没有可以响应的target,就直接return了。实际开发过程中是可以事先给一个固定的target专门用于在这个时候顶上,然后处理这种请求的
        return nil;
        }
    
    if ([target respondsToSelector:action]) {
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        return [target performSelector:action withObject:params];
    #pragma clang diagnostic pop
    } else {
        // 这里是处理无响应请求的地方,如果无响应,则尝试调用对应target的notFound方法统一处理
        SEL action = NSSelectorFromString(@"notFound:");
        if ([target respondsToSelector:action]) {
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
            return [target performSelector:action withObject:params];
    #pragma clang diagnostic pop
        } else {
            // 这里也是处理无响应请求的地方,在notFound都没有的时候,这个demo是直接return了。实际开发过程中,可以用前面提到的固定的target顶上的。
            return nil;
        }
    }
    }

模块间调度

    UIViewController *viewController = [[IComMediator sharedInstance]         
    IComMediator_DiscoverViewController:nil];
    [self.navigationController pushViewController:viewController animated:YES];

模块注册 每个模块注册IComMediator的Category后声明需要提供外部模块调用的类

#import "IComMediator+DynamicModuleActions.h"
// action 类名 Work 模块统一用Work
NSString * const kIComMediatorTargetDynamic = @"Dynamic";

// 类对应方法名
NSString * const kIComNativeFetchDynamicViewController = @"nativeFetchDynamicViewController";
NSString * const kIComNativeFetchDiscoverViewController = @"nativeFetchDiscoverViewController";
//DiscoverViewController


@implementation IComMediator (DynamicModuleActions)
- (UIViewController *)IComMediator_DynamicViewController:(NSDictionary *)params {
    UIViewController *viewController = [self performTarget:kIComMediatorTargetDynamic
                                                    action:kIComNativeFetchDynamicViewController
                                                    params:params];
    if ([viewController isKindOfClass:[UIViewController class]]) {
        // view controller 交付出去之后,可以由外界选择是push还是present
        return viewController;
    } else {
        // 这里处理异常场景,具体如何处理取决于产品
        return [[UIViewController alloc] init];
    }
}

模块声明

#ifndef ICModuleHeaderFile_h
#define ICModuleHeaderFile_h
#import "IComMediator+MineModuleActions.h"
#import "IComMediator+ApplicationActions.h"
#import "IComMediator+LoginModuleActions.h"
#import "IComMediator+JobModuleActions.h"
#import "IComMediator+SpaceModuleActions.h"
#import "IComMediator+MessageModuleActions.h"
#import "IComMediator+ContactsModuleActions.h"
#import "IComMediator+DynamicModuleActions.h"
#import "IComMediator+RedPacketModuleActions.h"
#import "IComMediator+Email.h"
#import "IComMediator+LifeCircleActions.h"

#import "IComMediator+Calendar.h"
#import "IComMediator+News.h"
#import "IComMediator+Window.h"

#import "IComMediator+ChatModuleActions.h"

#import "IComMediator+WeexSDK.h"
#endif /* ICModuleHeaderFile_h */

模块调用

case ICWindowRoomViewTypeGrow:
        {
            NSDictionary * dict = @{@"title":@"成长空间",@"spaceType":@2};
            UIViewController *viewController =[[IComMediator sharedInstance] IComMediator_SpaceViewController:dict];
            [self.navigationController pushViewController:viewController animated:YES];
        }
            break;
            
        case ICWindowRoomViewTypeInfor:
        {
            UIViewController *newsViewController = [[IComMediator sharedInstance] IComMediator_NewsViewController:nil];
            [self.navigationController pushViewController:newsViewController animated:YES];
        }
            break;
            
        case ICWindowRoomViewTypeCare:
        {
            //NSDictionary * dict = @{@"title":@"关怀空间",@"spaceType":@3};
            UIViewController *lifeCircleViewController = [[IComMediator sharedInstance] IComMediator_LifeCircleViewController:nil];
            [self.navigationController pushViewController:lifeCircleViewController animated:YES];
//            UIViewController *viewController =[[IComMediator sharedInstance] IComMediator_SpaceViewController:dict];
//            [self.navigationController pushViewController:viewController animated:YES];
        }break;
        ```
##2. TCP连接模块设计

![B215DD52-0EB9-4EA8-B342-CA7DCAB4C0F5.png](http://upload-images.jianshu.io/upload_images/1775503-da62d481d2c5d647.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

```flow
st=>start: TCP登录
islogin=>condition: TCP登录成功?
sendBeat=>operation: 创建轮询发送心跳请求
sendBeatStatus=>condition: 心跳包发送成功?
reSendBeat=>operation: 重新发送机制
isbeatFailOut=>condition: 失败次数超限?
reSendF=>operation: 失败次数达到上限后判断是否断开连接,做相应处理


reConnect=>operation: tcp断开重新连接机制
reIsSuccess=>condition: 重连接机?
disConnect=>condition: 断开连接?
alert=>operation: 提示用户无法正常连接

login=>operation: http登录
tcp=>operation: tcp注册登录
newdesc=>operation: 功能引导
rootVC=>operation: 主控制器
mainVC=>operation: 主页

e=>end

st->islogin
islogin(yes)->sendBeat->sendBeatStatus(yes)->e
sendBeatStatus(no)->isbeatFailOut(yes,right)->reConnect
isbeatFailOut(no)->e
disConnect(no,bottom)->e
islogin(no)->reConnect(right)->reIsSuccess
reIsSuccess(yes,left)->sendBeat
reIsSuccess(no)->alert->e

3. iCome数据同步机制流程

B3EBE84C-9FF0-47C6-99F7-F9300C91CBF9.png

st=>start: TCP登录成功
sync=>operation: imserver/groupList
syncStatus=>condition: grouplist?
saveDB=>operation: 修改(状态、未读数等)
updateGroupInfo=>operation: 更新群组信息
saveDB2=>operation: 存储群组最新消息
syncCmd=>operation: imserver/cmdList
syncCmdStatus=>condition: cmdList?
updateStatus=>operation: 同步本地的信息(修改头像、踢出群组、日程同步等)

e=>end
st->sync->syncStatus(yes)->saveDB->updateGroupInfo->saveDB2->syncCmd->updateStatus->e
syncStatus(no)->e

4. 消息发送机制

st=>start: 用户输入
isFile=>condition: file?
checkFile=>condition: 服务器存在?
createMessage=>operation: 创建消息体、生成消息唯一标识

sendFile=>operation: 创建临时消息体,发送文件拿到filekey

saveDB=>operation: 消息存储

sendMessage=>operation: 更新UI界面,消息发送
isSuccess=>condition:  消息发送成功?

disConnect=>condition: tcp连接?

update=>operation: 更新DB和UI
sendFail=>operation: 更新UI
sysReSend=>operation: tcp重新连接后系统重新发送

isTimeOut=>condition: 消息发送超时?
e=>end

st->isFile
isFile(yes)->checkFile
isFile(no)->createMessage->saveDB->sendMessage->disConnect(yes)->isSuccess
checkFile(yes,right)->createMessage
checkFile(no)->sendFile->createMessage
disConnect(no)->isTimeOut(no)->sysReSend->isSuccess
isTimeOut(yes)->sendFail
isSuccess(no)->sendFail->e
isSuccess(yes,right)->update->e

5.消息接收机制

进入聊天模块调用

st=>start
loadData=>operation: 本地数据库加载数据
cheak=>condition: db.lastId-db.firstId>=max?
repullMessage=>operation: repullMessage
saveDB=>operation: save DB
update=>operation: 更新UI界面
e=>end


st->loadData->cheak
cheak(yes)->repullMessage->saveDB->update->e
cheak(no)->update->e

消息返拉逻辑调用

st=>start
loadData=>operation: 本地数据库加载数据(data.firstId)
cheakCount=>condition: count>0?
cheak=>condition: data.firstId-db.firstId>=max?
repullMessage=>operation: repullMessage
cheakMaxId=>condition: maxId == nil?
isLastId=>condition: 最后一条数据?
update=>operation: 更新UI界面
e=>end

st->loadData->cheakCount
cheakCount(yes)->cheak
cheakCount(no)->cheakMaxId
cheakMaxId(yes)->repullMessage
cheakMaxId(no)->isLastId
isLastId(yes, right)->update
isLastId(no)->repullMessage
cheak(yes)->repullMessage->update->e
cheak(no)->update->e

消息接收逻辑调用

st=>start
tcpReceived=>operation: messageDidReceived
cmd=>condition: isCmd ?
updateCmd=>operation: updateCmdList
cmdListAction=>operation: 处理对应action
cheak=>condition: messageType == 0
groupList=>operation: updateGroupList
isExist=>condition: groupIsExist?
updateGroupStatus=>operation: 更新状态、未读、声音提示等信息
saveDB=>operation: 消息存储到本地数据库
update=>operation: 通知更新聊天与消息列表界面
e=>end


st->tcpReceived->cmd
cmd(yes,right)->updateCmd->cmdListAction->e
cmd(no)->cheak
cheak(yes, right)->groupList->e
cheak(no)->isExist
isExist(yes)->updateGroupStatus->saveDB->update->e
isExist(no)->groupList->e

6. 数据存储

C6CB068E-0EA6-4AA7-BD03-6F3DC90781CD.png

7. JS与WKWebView交互模块

st=>start: 协议定制
jsrequest=>operation: js请求
isBase=>condition: 基础接口?
isValidData=>condition: ValidData?
validData=>operation: 权限校验
hasPermission=>condition: 权限?
load=>operation: 调用客户端逻辑
loadSuccess=>condition: isSuccess?
success=>operation: 成功回调
fail=>operation: 错误回调

e=>end
st->jsrequest->isBase
isBase(yes)->load->loadSuccess
isBase(no)->hasPermission
hasPermission(yes)->load
hasPermission(no)->validData->loadSuccess
loadSuccess(yes)->success->e
loadSuccess(no)->fail->e

8. 页面统一调用逻辑

通过URL Router方式处理原生、网页、weex页面的调用

- (void)pushCustomViewControllerURL:(NSString *)URL
                 fromViewController:(UIViewController *)ViewController
                           animated:(BOOL)animated {
                           if ([URL hasPrefix:@"icome"]) { // 打开本地自定义界面
        NSString *tempUrl = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *pushUrl = [NSURL URLWithString:tempUrl];
        NSString *scheme = pushUrl.scheme;
        NSString *host = pushUrl.host;
        NSString *path = pushUrl.path;
        NSString *query = pushUrl.query;
        
        NSDictionary *queryDict = nil;
        if (!kStringIsEmpty(query)) {
            queryDict = [NSDictionary dictionaryWithURLQuery:query];
        }
        NSString *coustId = nil;
        if (!kStringIsEmpty(path)) {
            coustId = [[path componentsSeparatedByString:@"/"] objectAtIndex:1]; //
        }
        
        NSString *class = host;
        // 日程
        if ([class isEqualToString:@"schedule"]) {
            NSDictionary *param = nil;
            if (!kStringIsEmpty(queryDict[@"beginDate"])) {
                param = @{@"beginDate":queryDict[@"beginDate"]};
            }
            UIViewController *viewController = [[IComMediator sharedInstance] IComMediator_CalendarViewController:param];
            [ViewController.navigationController pushViewController:viewController animated:YES];
        }
        
 }

9. 第三方使用

source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0'

target 'ICome' do

pod 'FMDB', '~> 2.6.2'
pod 'MBProgressHUD',    '~> 1.0.0'
pod 'Masonry',  '~> 1.0.2'
pod 'SDWebImage',   '~> 3.7.6' #修改过源代码 请勿更新
pod 'CocoaAsyncSocket', '~> 7.4.3'
pod 'SSKeychain',   '~> 1.4.0'
pod 'MJExtension',  '~> 3.0.10'
pod 'YYKit',    '~> 1.0.5' #修改过源代码 请勿更新
pod 'MLLabel',  '~> 1.9.1' #修改过源代码 请勿更新
pod 'UITableView+FDTemplateLayoutCell', '~> 1.4'
pod 'AFNetworking', '~> 3.1.0'
pod 'BaiduMapKit',  '~> 3.3.1'
pod 'MJRefresh',    '~> 3.1.12'
pod 'UMengAnalytics',   '~> 4.2.4'
pod 'FDFullscreenPopGesture',   '~>1.1'
pod 'CYLTabBarController',  '~> 1.6.0' #修改过源代码 请勿更新
pod 'CocoaLumberjack',  '~> 3.0.0' #修改过源代码 请勿更新
pod 'JSPatchPlatform', '~> 1.6.4'
pod 'TZImagePickerController',  '1.7.9'  #修改过源代码 请勿更新
pod 'mailcore2-ios', '0.6.4'
pod 'DKNightVersion', '2.4.3'
pod 'LKDBHelper', '2.4.2'
pod 'Bugtags'

end

10. 后期架构调整

邮箱登录逻辑

st=>start: 进入邮箱界面
sync=>operation: 默认邮箱地址进行登录
syncStatus=>condition: 邮箱登录成功?

saveDB=>operation: 保存邮箱地址与密码供下次登录
mailLogin=>operation: 邮箱登录界面
userEdt=>operation: 用户编辑邮箱信息登录
check=>condition: 本地校验邮箱格式?
login=>operation: 登录中..
loginStatus=>condition: 第二次登录是否成功?
traverseLogin=>operation: 遍历登录邮箱...

e=>end


st->sync->syncStatus(yes, right)->saveDB->e
syncStatus(no)->mailLogin->userEdt->check(yes)->login->loginStatus(yes)->saveDB->e


check(no)->userEdt
loginStatus(no)->traverseLogin->saveDB->e

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • app框架整体设计

    程序员不务正业
  • UIScrollView初始位置变化的问题

    程序员不务正业
  • Promise与Callback函数

    1,callback函数处理异步:代码逻辑复杂,可读性差----回调地狱;不可return; 2,promise处理异步: 对比callback,易读,可以...

    程序员不务正业
  • 计算机图形学课程设计内容及要求

    目标:以图形学算法为目标,深入研究。继而策划、设计并实现一个能够表现计算机图形学算法原理的或完整过程的演示系统,并能从某些方面作出评价和改进意见。通过完成一个完...

    步行者08
  • SIGGRAPH最佳博士论文奖又落华人手中,胡渊鸣的这位师兄不一般

    这已经是「连续3年」,该重要奖项颁给华人学者,此前分别由加州大学伯克利分校闫令琪博士和朱俊彦博士摘得。

    量子位
  • 谷歌发现机器视觉的“阿喀琉斯之踵”

    ---- 现代科技最引人注目的进步之一是机器视觉的兴起。在短短的几年间,新一代的机器学习技术已经改变了计算机对图像的识别方法。现在,机器在人脸识别和物体识别方面...

    人工智能快报
  • Oracle 10g RAC OCR、Voting disk更换

    环境:OEL 5.7 + Oracle 10.2.0.5 RAC 需求:更换存储,OCR、Voting disk同时需要更换到新存储。

    Alfred Zhao
  • 【周日鸡汤】-我在前端工作的头几年中所走过的弯路

    做为一个前端开发方面的公众号,我一直想告诉同学们,如何才能成为一个优秀的前端开发工程师。也许是我的经历与你的感受之间有着不可跨越的鸿沟,我总觉得有力使不上。 那...

    web前端教室
  • 深度学习研究总结:生成对抗网络(附 3 篇 arXiv 最火论文)

    【新智元导读】Yann LeCun曾说:“对抗训练是切片面包发明以来最令人激动的事情”。这篇文章中,作者回顾基于 Ian Goodfellow 在2014 年的...

    新智元
  • .Net高级进阶,在复杂的业务逻辑下,如何以最简练的代码,最直观的编写事务代码?

    本文将通过场景例子演示,来通俗易懂的讲解在复杂的业务逻辑下,如何以最简练的代码,最直观的编写事务代码。

    小曾看世界

扫码关注云+社区

领取腾讯云代金券