GithubHelp home page GithubHelp logo

im_ios's Introduction

#gobelieve iOS gobelieve iOS SDK

##生成demo的workspace

  1. cp demo/dev.podspec ./
  2. pod install

##应用集成到自己的客户端

  1. podfile

     pod 'gobelieve', :git => 'https://github.com/GoBelieveIO/im_ios.git'
    
  2. 在AppDelegate初始化deviceID以及message handler

     [IMService instance].deviceID = deviceID;
     [IMService instance].peerMessageHandler = [PeerMessageHandler instance];
     [IMService instance].groupMessageHandler = [GroupMessageHandler instance];
     [IMService instance].customerMessageHandler = [CustomerMessageHandler instance];
    
  3. 在AppDelegate中监听系统网络变化

     -(void)startRechabilityNotifier {
         self.reach = [GOReachability reachabilityForInternetConnection];
         self.reach.reachableBlock = ^(GOReachability*reach) {
             dispatch_async(dispatch_get_main_queue(), ^{
                 NSLog(@"internet reachable");
                 [[IMService instance] onReachabilityChange:YES];
             });
         };
         
         self.reach.unreachableBlock = ^(GOReachability*reach) {
             dispatch_async(dispatch_get_main_queue(), ^{
                 NSLog(@"internet unreachable");
                 [[IMService instance] onReachabilityChange:NO];
             });
         };
         
         [self.reach startNotifier];
    
     }
    
     [self startRechabilityNotifier];
     [IMService instance].reachable = [self.reach isReachable];
    
  4. 登录成功之后设置token和uid, token和uid从应用本身的登录接口获得

     [IMService instance].token = ""
     [PeerMessageHandler instance].uid = uid
     [GroupMessageHandler instance].uid = uid
     [CustomerMessageHandler instance].uid = uid
    
     SyncKeyHandler *handler = [[SyncKeyHandler alloc] initWithFileName:fileName];
     [IMService instance].syncKeyHandler = handler;
    
  5. 初始化消息db

     NSFileManager *fileManager = [NSFileManager defaultManager];
     if (![fileManager fileExistsAtPath:dbPath]) {
         NSString *p = [[NSBundle mainBundle] pathForResource:@"gobelieve" ofType:@"db"];
         [fileManager copyItemAtPath:p toPath:dbPath error:nil];
     }
     FMDatabase *db = [[FMDatabase alloc] initWithPath:dbPath];
     BOOL r = [db openWithFlags:SQLITE_OPEN_READWRITE|SQLITE_OPEN_WAL vfs:nil];
     if (!r) {
         NSLog(@"open database error:%@", [db lastError]);
         db = nil;
         NSAssert(NO, @"");
     }
    
     [PeerMessageDB instance].db = db;
     [GroupMessageDB instance].db = db;
     [CustomerMessageDB instance].db = db;
    
  6. 启动IMService开始接受消息

     [[IMService instance] start];
    
  7. 添加消息observer,处理相应类型的消息

     //连接状态
     [[IMService instance] addConnectionObserver:ob];
    
     //点对点消息
     [[IMService instance] addPeerMessageObserver:ob];
     //群组消息
     [[IMService instance] addGroupMessageObserver:ob];
     //直播的聊天室消息
     [[IMService instance] addRoomMessageObserver:ob];
     //实时消息,用于voip的信令
     [[IMService instance] addRTMessageObserver:ob];
     //系统消息
     [[IMService instance] addSystemMessageObserver:ob];
    
  8. app进入后台,断开socket链接

     [[IMService instance] enterBackground];
    
  9. app返回前台,重新链接socket

    [[IMService instance] enterForeground]; 
    
  10. 发送点对点消息

    PeerMessageViewController* msgController = [[PeerMessageViewController alloc] init];
    msgController.peerUID = peerUID;
    msgController.peerName = @"";
    msgController.currentUID = uid;
    [self.navigationController pushViewController:msgController animated:YES];
    
  11. 发送群组消息

    GroupMessageViewController* msgController = [[GroupMessageViewController alloc] init];
    msgController.groupID = groupID;
    msgController.groupName = @"";
    msgController.currentUID = uid;
    [self.navigationController pushViewController:msgController animated:YES];
    
  12. 用户注销

    [[IMService instance] stop]
    

im_ios's People

Contributors

richmonkey avatar chisj avatar daibou007 avatar

Watchers

James Cloos 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.