当掉线时,IOS SDK会自动重连,只需要监听重连相关的回调,无需进行任何操作。
//
// MessageViewController.m
#import "MessageViewController.h"
#import "EaseMob.h"
@interface MessageViewController ()
@end
@implementation MessageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置标题
self.title = @"消息";
}
/*!
@method
@brief 将要发起自动重连操作时发送该回调
@discussion
@result
*/
- (void)willAutoReconnect
{
self.title = @"网络连接中...";
}
/*!
@method
@brief 自动重连操作完成后的回调(成功的话,error为nil,失败的话,查看error的错误信息)
@discussion
@result
*/
- (void)didAutoReconnectFinishedWithError:(NSError *)error
{
self.title = @"消息";
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return 0;
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
*/
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
@end
本文介绍了iOS SDK在遇到网络断开时如何自动重新连接的实现机制。通过监听回调,开发者可以了解重连状态,无需额外操作。示例代码展示了如何在iOS应用中使用EaseMob SDK实现这一功能。
3189

被折叠的 条评论
为什么被折叠?



