我正在尝试将 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 文档可以在这里找到: