SendBird SDK方法的Rubymotion翻译
Rubymotion translation of SendBird SDK methods
我正在开发与 Rubymotion 的 SendBird 聊天集成。我 运行 遇到了一些问题,因为我对 Objective-C / Swift 结构的了解有限,无法从 SDK 获取消息通道列表。
如果能帮我将以下代码转换为 RubyMotion 代码,我将不胜感激:
Objective-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) {
}];
}
Swift:
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)
在这种情况下,我真的不知道如何正确设置块。
好的。所以 nextWithResultBlock 实际上也需要传递 endBlock,所以这终于解决了它:
@messagingChannelListQuery.nextWithResultBlock(
-> (queryresult) {
#do something here with queryresult.each
},
endBlock: -> (code) {
}
)
NoMethodError 让我失望。
我正在开发与 Rubymotion 的 SendBird 聊天集成。我 运行 遇到了一些问题,因为我对 Objective-C / Swift 结构的了解有限,无法从 SDK 获取消息通道列表。
如果能帮我将以下代码转换为 RubyMotion 代码,我将不胜感激:
Objective-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) {
}];
}
Swift:
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)
在这种情况下,我真的不知道如何正确设置块。
好的。所以 nextWithResultBlock 实际上也需要传递 endBlock,所以这终于解决了它:
@messagingChannelListQuery.nextWithResultBlock(
-> (queryresult) {
#do something here with queryresult.each
},
endBlock: -> (code) {
}
)
NoMethodError 让我失望。