Code Monkey home page Code Monkey logo

leanchat-ios's Introduction

image

介绍

这个示例项目是为了帮助使用 LeanCloud 的开发者快速实现具有实时通讯功能的应用。

子项目介绍

  • LeanChatLib ,聊天界面与逻辑的封装库
  • LeanChatExample,展示了如何用少量代码调用LeanChatLib,加入聊天
  • LeanChat-ios,为LeanChat IM 整个应用,包含了对 LeanChatLib 更复杂的运用。

分支

  • master 分支,使用了 LeanCloud 的实时通信服务2.0 (推荐)
  • v1 分支,使用了 LeanCloud 的实时通信服务 1.0

运行

  • 打开 LeanChat.xcworkspace

如何三步加入IM

  1. LeanCloud 中创建应用
  2. 创建项目,加入 LeanChatLib 作为Library,复制几个文件,
    qq20150403-4
  3. 依次在合适的地方加入以下代码,

应用启动后,

   [AVOSCloud setApplicationId: YourAppID clientKey: YourAppKey];

登录时,

        CDIM* im=[CDIM sharedInstance];
        im.userDelegate=[CDIMService shareInstance];
        [im openWithClientId:self.selfIdTextField.text callback:^(BOOL succeeded, NSError *error) {
            if(error){
                DLog(@"%@",error);
            }else{
                [self performSegueWithIdentifier:@"goMain" sender:sender];
            }
        }];

和某人聊天,

    [[CDIMService shareInstance] goWithUserId:self.otherIdTextField.text fromVC:self];

注销时,

    [[CDIM sharedInstance] closeWithCallback:^(BOOL succeeded, NSError *error) {
        DLog(@"%@",error);
    }];

然后,就可以像上面截图那样聊天了。

至于配置用户名、用户头像,可完善下面这个 delegate,

@protocol CDUserModel <NSObject>

-(NSString*)userId;
-(NSString*)avatarUrl;
-(NSString*)username;

@end

@protocol CDUserDelegate <NSObject>

@required

// run in main queue
-(id<CDUserModel>) getUserById:(NSString*)userId;

// please cache users which will be used by getUserById
-(void)cacheUserByIds:(NSSet*)userIds block:(AVIMArrayResultBlock)block;

@end

使用 LeanChatLib 需知

  1. 如何引入LeanChatLib 依赖? 首先,打开LeanChatLib文件夹,拖动到你的项目中,如图,

qq20150407-1

之后,项目依赖图,如,

qq20150407-2

也可以建立一个workspace,使得项目依赖如图,

qq20150407-4

之后可以进行第二点和第三点。
2. 必须允许 LeanChatLib中的项目直接include framework里的头文件,设置选项为 YES,如图, qq20150403-1
3. 加入 embededLib,

qq20150407-3

qq20150403-3

部署 LeanChat 需知

如果要部署完整的LeanChat的话,因为该应用有添加好友的功能,请在设置->应用选项中,勾选互相关注选项,以便一方同意的时候,能互相加好友。

qq20150407-5

开发指南

实时通信服务开发指南

Wiki

更多介绍

致谢

感谢曾宪华大神的 MessageDisplayKit 开源库。

leanchat-ios's People

Contributors

jwfing avatar lzwjava avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.