0

我正在开发与 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
    })
}

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

红宝石运动:

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)

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

4

1 回答 1

0

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

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

NoMethodError 让我失望。

于 2016-08-08T02:57:11.320 回答