首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SendBird chat SDK Rubymotion集成

SendBird chat SDK Rubymotion集成
EN

Stack Overflow用户
提问于 2016-08-03 14:58:42
回答 1查看 159关注 0票数 0

我正在尝试将SendBird SDK聊天与Rubymotion (通过它的CocoaPod)集成起来。

最初的步骤可以很好地工作,并且我已经能够将吊舱添加到我的Rakefile中(使用),没有问题地编译,登录用户并创建消息通道。然而,事件处理程序让我感到困惑。

以下是我能够从SendBird文档中转换的步骤:

在app委托中的初始化

SendBird目标C:

代码语言:javascript
复制
#import <SendBirdSDK/SendBirdSDK.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // ...
    NSString *APP_ID = @"<YOUR_APP_ID>"; // You could get it from SendBird Dashboard.
    [SendBird initAppId:APP_ID];
    // ...
    return YES;
}

Rubymotion:

代码语言:javascript
复制
APP_ID = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
SendBird.initAppId(APP_ID)

在我的应用程序中登录/注册时,登录到SendBird

SendBird目标C:

代码语言:javascript
复制
- (void)viewDidLoad
{    
    // other setup code
    [SendBird loginWithUserId:USER_ID andUserName:USER_NICKNAME];   
}

Rubymotion:

(一旦登录,我就将用户信息存储在Auth.current_user哈希中)

代码语言:javascript
复制
SendBird.loginWithUserId(Auth.current_user["id"],andUserName:Auth.current_user["name"])

创建消息通道并设置事件处理程序

SendBird目标C:

代码语言:javascript
复制
[SendBird startMessagingWithUserId:targetUserId]; // 1 on 1 channel

// In your event handler
[SendBird setEventHandlerConnectBlock:^(SendBirdChannel *channel) {
    // Callback for [SendBird connectWithTS:] or [SendBird connect:]
} errorBlock:^(NSInteger code) {
    // Error occured due to bad APP_ID (or other unknown reason)
} channelLeftBlock:^(SendBirdChannel *channel) {
    // Callback for [SendBird leaveChannel:]
} messageReceivedBlock:^(SendBirdMessage *message) {
    // Received a regular chat message
} fileReceivedBlock:^(SendBirdFileLink *fileLink) {
    // Received a file
} messagingStartedBlock:^(SendBirdMessagingChannel *channel) {
    // Callback for [SendBird startMessagingWithUserId:] or [SendBird inviteMessagingWithChannelUrl:]
} messagingUpdatedBlock:^(SendBirdMessagingChannel *channel) {
    // Callback for [SendBird inviteMessagingWithChannelUrl:]
} messagingEndedBlock:^(SendBirdMessagingChannel *channel) {
    // Callback for [SendBird endMessagingWithChannelUrl:]
} allMessagingEndedBlock:^ {
    // Callback for [SendBird endAllMessaging:]
} readReceivedBlock:^(SendBirdReadStatus *status) {
    // When ReadStatus has been received
} messageDeliveryBlock:^(BOOL send, NSString *message, NSString *data, NSString *tempId{
   // To determine the message has been successfully sent.
} mutedMessagesReceivedBlock:^(SendBirdMessage *message) {
   // When soft-muted messages have been received
} mutedFileReceivedBlock:^(SendBirdFileLink *message) {
   // When soft-muted files have been received
}];

Rubymotion:

我遇到麻烦了。我能够创建消息通道,但我不知道如何在Rubymotion中编写Objective事件处理程序。http://objc2rubymotion.herokuapp.com/的联机翻译程序由于^和*语法而失败。任何帮助都是非常感谢的。

代码语言:javascript
复制
SendBird.startMessagingWithUserId(id_of_target_user)

#Event Handler

编辑:

一个比我更了解Rubymotion的朋友为我指明了正确的方向,所以现在我有了以下事件处理程序:

代码语言:javascript
复制
SendBird.startMessagingWithUserId(2)

SendBird.setEventHandlerConnectBlock(
    -> (channel) {
            # handle connect
    },
    messagingStartedBlock: -> (channel) {
      mp "channel created:" + channel.to_s
    })

但是,对于NoMethodError来说,这是失败的:

代码语言:javascript
复制
2016-08-03 19:48:58.711 faces_ios_v1[75673:798798] chat_screen.rb:24:in `on_load': undefined method `setEventHandlerConnectBlock:messagingStartedBlock:' for SendBird:Class (NoMethodError)
    from screen_module.rb:39:in `view_did_load'
    from view_controller.rb:15:in `viewDidLoad'
2016-08-03 19:48:58.723 faces_ios_v1[75673:798798] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'chat_screen.rb:24:in `on_load': undefined method `setEventHandlerConnectBlock:messagingStartedBlock:' for SendBird:Class (NoMethodError)
    from screen_module.rb:39:in `view_did_load'
    from view_controller.rb:15:in `viewDidLoad'

如果在事件处理程序中不包括messagingStartedBlock,则会得到以下错误:

代码语言:javascript
复制
2016-08-03 19:35:20.120 faces_ios_v1[74958:793380] chat_screen.rb:14:in `on_load': undefined method `setEventHandlerConnectBlock' for SendBird:Class (NoMethodError)
    from screen_module.rb:39:in `view_did_load'
    from view_controller.rb:15:in `viewDidLoad'
2016-08-03 19:35:20.132 faces_ios_v1[74958:793380] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'chat_screen.rb:14:in `on_load': undefined method `setEventHandlerConnectBlock' for SendBird:Class (NoMethodError)
    from screen_module.rb:39:in `view_did_load'
    from view_controller.rb:15:in `viewDidLoad'

这是没有意义的,因为setEventHandlerConnectBlock显然应该是SendBird类的一个方法。

相关的SendBird SDK文档可以在这里找到:

channel

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-04 02:56:48

好吧,这件事是在一个朋友的帮助下解决的。

结果是,SendBird事件处理程序方法需要传递所有事件块,否则它将无法工作。所以这是可行的:

代码语言:javascript
复制
  SendBird.startMessagingWithUserId(2)

    SendBird.setEventHandlerConnectBlock(
  -> (channel) { },
  errorBlock: -> (code) { },
  channelLeftBlock: -> (channel) { },
  messageReceivedBlock: -> (message) { },
  systemMessageReceivedBlock: -> (message) { },
  broadcastMessageReceivedBlock: -> (message) { },
  fileReceivedBlock: -> (file_link) { },
  messagingStartedBlock: -> (channel) {
    mp "Messaging started"
    mp channel
   },
  messagingUpdatedBlock: -> (channel) { },
  messagingEndedBlock: -> (channel) { },
  allMessagingEndedBlock: -> { },
  messagingHiddenBlock: -> (channel) { },
  allMessagingHiddenBlock: -> { },
  readReceivedBlock: -> (status) { },
  typeStartReceivedBlock: -> (status) { },
  typeEndReceivedBlock: -> (status) { },
  allDataReceivedBlock: -> (sendBirdDataType, count) { },
  messageDeliveryBlock: -> (send, message, data, temp_id) { },
  mutedMessagesReceivedBlock: -> (message) { },
  mutedFileReceivedBlock: -> (message) { }
)

并将输出:

代码语言:javascript
复制
"Messaging started"
#<SendBirdMessagingChannel:0x10f9bcdc0>

一旦我实现了这个集成,我将上传一个教程/ github项目。

完成后,我会把链接发回作为评论。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38747161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档