• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

GoBelieveIO/im_ios: GoBelieveIO IM iOS sdk

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

GoBelieveIO/im_ios

开源软件地址:

https://github.com/GoBelieveIO/im_ios

开源编程语言:

Objective-C 96.7%

开源软件介绍:

#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]
    



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
apptentive/apptentive-ios: Apptentive Legacy SDK for iOS. See https://github.com ...发布时间:2022-06-21
下一篇:
confirmedcode/Lockdown-iOS发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap