SendBird SDK方法的Rubymotion翻译

时间:2016-08-08 00:22:04

标签: rubymotion sendbird

我正在与Rubymotion进行SendBird聊天集成。由于我对Objective-C / Swift结构的了解有限,我无法从SDK获取消息传递通道列表,因此我遇到了一些问题。

我很感激帮助将以下代码翻译成RubyMotion代码:

目标-C:

- (void) queryMessagingChannels
{
    messagingChannelListQuery = [SendBird queryMessagingChannelList];
    [messagingChannelListQuery setLimit:15];
    [messagingChannelListQuery nextWithResultBlock:^(NSMutableArray *queryResult) {
        ...
        for (int i = 0; i < [queryResult count]; i++) {
            SendBirdMessagingChannel *mc = (SendBirdMessagingChannel *)[queryResult objectAtIndex:i];
            ...
        }
        ...
    } endBlock:^(NSError *error) {
    }];
}

夫特:

func queryMessagingChannels() {
    messagingChannelListQuery = SendBird.queryMessagingChannelList()
    messagingChannelListQuery?.setLimit(15)
    messagingChannelListQuery?.nextWithResultBlock({ (queryResult) -> Void in
        ....
        for model in queryResult {
            let mc: SendBirdMessagingChannel = model as! SendBirdMessagingChannel
            ....
        }
        ....
        }, endBlock: { (code) -> Void in
    })
}

到目前为止,我有这个,但它失败了,错误。

Rubymotion:

mp "Iterating over MessagingChannelList"
@messagingChannelListQuery = SendBird.queryMessagingChannelList()
@messagingChannelListQuery.setLimit(5)
@messagingChannelListQuery.nextWithResultBlock.each do |queryResult|
  @messaging_channels << queryResult
end
# reload tableview data here

错误:

chat_messaging_screen.rb:49:in `load_async': undefined method `nextWithResultBlock' for #<SendBirdMessagingChannelListQuery:0x117c672e0> (NoMethodError)

在这种情况下,我真的不知道如何正确设置块。

1 个答案:

答案 0 :(得分:0)

确定。所以nextWithResultBlock实际上也需要传递endBlock,所以这最终解决了它:

@messagingChannelListQuery.nextWithResultBlock(
  -> (queryresult) {
  #do something here with queryresult.each
  },
  endBlock: -> (code) {
  }
)

NoMethodError让我失望。