位置实时共享

注意

仅支持单聊

下面以 Demo 中的代码为例,说明集成步骤。以下代码,可以在 SealTalkRCDChatViewController.m 中找到。

SealTalk 源码下载地址

引入头文件

//RCDChatViewController Class

#import "RealTimeLocationEndCell.h"
#import "RealTimeLocationStartCell.h"
#import "RealTimeLocationStatusView.h"
#import "RealTimeLocationViewController.h"

设置协议和代理

//RCDChatViewController Class

@interface RCDChatViewController () < RCRealTimeLocationObserver,
    RealTimeLocationStatusViewDelegate>
@property(nonatomic, weak) id<RCRealTimeLocationProxy> realTimeLocation;
@property(nonatomic, strong)
    RealTimeLocationStatusView *realTimeLocationStatusView;

注册自定义消息 Cell

//RCDChatViewController Class

  [self registerClass:[RealTimeLocationStartCell class]
      forMessageClass:[RCRealTimeLocationStartMessage class]];
  [self registerClass:[RealTimeLocationEndCell class]
      forMessageClass:[RCRealTimeLocationEndMessage class]];

获取实时位置共享服务,并配置给当前类。

//RCDChatViewController Class

__weak typeof(&*self) weakSelf = self;
  [[RCRealTimeLocationManager sharedManager]
      getRealTimeLocationProxy:self.conversationType
      targetId:self.targetId
      success:^(id<RCRealTimeLocationProxy> realTimeLocation) {
        weakSelf.realTimeLocation = realTimeLocation;
        [weakSelf.realTimeLocation addRealTimeLocationObserver:self];
        [weakSelf updateRealTimeLocationStatus];
      }
      error:^(RCRealTimeLocationErrorCode status) {
        NSLog(@"get location share failure with code %d", (int)status);
      }];

在点击位置时弹出位置实时共享

//RCDChatViewController Class

- (void)pluginBoardView:(RCPluginBoardView *)pluginBoardView
     clickedItemWithTag:(NSInteger)tag {
  switch (tag) {
  case PLUGIN_BOARD_ITEM_LOCATION_TAG: {
    if (self.realTimeLocation) {
      UIActionSheet *actionSheet = [[UIActionSheet alloc]
                   initWithTitle:nil
                        delegate:self
               cancelButtonTitle:@"取消"
          destructiveButtonTitle:nil
               otherButtonTitles:@"发送位置", @"位置实时共享", nil];
      [actionSheet showInView:self.view];
    } else {
      [super pluginBoardView:pluginBoardView clickedItemWithTag:tag];
    }

  } break;

点击 actionSheet 执行位置实时共享

//RCDChatViewController Class

- (void)actionSheet:(UIActionSheet *)actionSheet
    clickedButtonAtIndex:(NSInteger)buttonIndex {
  switch (buttonIndex) {
  case 0: {
    [super pluginBoardView:self.pluginBoardView
        clickedItemWithTag:PLUGIN_BOARD_ITEM_LOCATION_TAG];
  } break;
  case 1: {
    [self showRealTimeLocationViewController];
  } break;
  }
}

将上面所有方法以及方法中相关的的代码都拷贝到工程中,就可以正常使用位置实时共享功能了。