0

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

最初的步骤工作正常,我已经能够将 pod 添加到我的 Rakefile(使用 motion-cocoapods)并毫无问题地编译,登录用户并创建消息传递通道。但是,事件处理程序让我很难过。

这些是我能够从 SendBird 文档中翻译的步骤:

在应用委托中初始化

SendBird 目标 C:

#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;
}

红宝石运动:

APP_ID = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
SendBird.initAppId(APP_ID)

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

SendBird 目标 C:

- (void)viewDidLoad
{    
    // other setup code
    [SendBird loginWithUserId:USER_ID andUserName:USER_NICKNAME];   
}

红宝石运动:

(登录后我将用户信息存储在 Auth.current_user 哈希中)

SendBird.loginWithUserId(Auth.current_user["id"],andUserName:Auth.current_user["name"])

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

SendBird 目标 C:

[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 中编写该 Objective-C 事件处理程序。 由于 ^ 和 * 语法,http: //objc2rubymotion.herokuapp.com/上的在线翻译器失败。任何帮助表示赞赏。

SendBird.startMessagingWithUserId(id_of_target_user)

#Event Handler

编辑:

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

SendBird.startMessagingWithUserId(2)

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

但是,这会因 NoMethodError 而失败:

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在事件处理程序中,我会收到以下错误:

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 文档可以在这里找到:

https://docs.sendbird.com/ios#messaging_channel

4

1 回答 1

0

好的,经过朋友的大力帮助,这个问题得到了解决。

事实证明,SendBird 事件处理程序方法需要传递所有事件块,否则它将不起作用。所以这将起作用:

  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) { }
)

并将输出:

"Messaging started"
#<SendBirdMessagingChannel:0x10f9bcdc0>

一旦我得到这个集成工作,我将上传一个教程/github项目。

完成后我会将链接作为评论发回

于 2016-08-04T02:56:48.770 回答