BMXClient Class Reference
Inherits from NSObject
Declared in BMXClient.h
Properties
chatService
@property (nonatomic, strong, readonly) id<BMXChatManager> chatService
groupService
@property (nonatomic, strong, readonly) id<BMXGroupManager> groupService
pushService
@property (nonatomic, strong, readonly) id<BMXPushManager> pushService
rosterService
@property (nonatomic, strong, readonly) id<BMXRosterManager> rosterService
sdkConfig
@property (nonatomic, strong) BMXSDKConfig *sdkConfig
userService
@property (nonatomic, strong, readonly) id<BMXUserManager> userService
Class Methods
getCacheDir
+ (NSString *)getCacheDir
sharedClient
+ (instancetype)sharedClient
Instance Methods
UILabel *label1 = [[UILabel alloc] init];
label1.textAlignment = NSTextAlignmentCenter;
label1.font = [UIFont systemFontOfSize:14];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
label1.text = [NSString stringWithFormat:NSLocalizedString(@"Maximtop_IM__v", @"蓝莺IM v%@"), app_Version];
[self.view addSubview:label1];
UILabel *label2 = [[UILabel alloc] init];
BMXSDKConfig *config = [[BMXClient sharedClient] sdkConfig];
- (void)loadAccountData {
NSArray *list = [AccountListStorage loadObject];
self.accountArray = list;
IMAcount *a = self.accountArray[0];
[[[BMXClient sharedClient] rosterService] searchByRosterId:[a.usedId integerValue] forceRefresh:YES completion:^(BMXRoster *roster, BMXError *error) {
- (void)loginWithaccount:(IMAcount *)account {
[HQCustomToast showWating];
[HostConfigManager sharedManager].IMServer = account.IMServer;
[HostConfigManager sharedManager].IMPort = account.IMPort;
[HostConfigManager sharedManager].restServer = account.restServer;
[[HostConfigManager sharedManager] updataConfig];
[[BMXClient sharedClient] changeAppID:account.appid completion:^(BMXError * _Nonnull error) {
- (void)signByaccount:(IMAcount *)account {
[[BMXClient sharedClient] signInByName:account.userName password:account.password completion:^(BMXError * _Nonnull error) {
- (void)bindDeviceToken {
NSString *deviceToken = [[NSUserDefaults standardUserDefaults] valueForKey:@"deviceToken"];
if ([deviceToken length]) {
[[[BMXClient sharedClient] userService] bindDevice:deviceToken completion:^(BMXError *error) {
- (void)getProfile {
[[[BMXClient sharedClient] userService] getProfileForceRefresh:YES completion:^(BMXUserProfile *profile, BMXError *aError) {
[[[BMXClient sharedClient] userService] getProfileForceRefresh:YES completion:^(BMXUserProfile *profile, BMXError *aError) {
if (!aError) {
IMAcount *account = [IMAcountInfoStorage loadObject];
account.usedId = [NSString stringWithFormat:@"%lld", profile.userId];
account.userName = profile.userName;
[IMAcountInfoStorage saveObject:account];
account.appid = [[BMXClient sharedClient] sdkConfig].appID;
[[[BMXClient sharedClient] userService] getProfileForceRefresh:YES completion:^(BMXUserProfile *profile, BMXError *aError) {
if (!aError) {
IMAcount *account = [IMAcountInfoStorage loadObject];
account.usedId = [NSString stringWithFormat:@"%lld", profile.userId];
account.userName = profile.userName;
[IMAcountInfoStorage saveObject:account];
account.appid = [[BMXClient sharedClient] sdkConfig].appID;
[self saveAccountToLoaclListWithaccount:account];
[[[BMXClient sharedClient] userService] downloadAvatarWithProfile:profile thumbnail:YES progress:^(int progress, BMXError *error) {
changeAppID:completion:
更改SDK的appId,本操作会同时更新BMXConfig中的appId。
- (void)changeAppID:(NSString *)*appID* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Parameters
appID
新变更的appId
Discussion
更改SDK的appId,本操作会同时更新BMXConfig中的appId。
Declared In
BMXClient.h
- (void)loginWithaccount:(IMAcount *)account {
[HQCustomToast showWating];
[HostConfigManager sharedManager].IMServer = account.IMServer;
[HostConfigManager sharedManager].IMPort = account.IMPort;
[HostConfigManager sharedManager].restServer = account.restServer;
[[HostConfigManager sharedManager] updataConfig];
[[BMXClient sharedClient] changeAppID:account.appid completion:^(BMXError * _Nonnull error) {
- (void)reloadAppID:(NSString *)appid {
[AppIDManager changeAppid:appid isSave:NO];
[[BMXClient sharedClient] changeAppID:appid completion:^(BMXError * _Nonnull error) {
connectStatus
获取当前和服务器的连接状态
- (BMXConnectStatus)connectStatus
Discussion
获取当前和服务器的连接状态
Declared In
BMXClient.h
disConnect
断开网络连接
- (void)disConnect
Discussion
断开网络连接
Declared In
BMXClient.h
- (void)applicationDidEnterBackground:(UIApplication *)application {
//进入后台
[[BMXClient sharedClient] disConnect];
- (void)applicationWillTerminate:(UIApplication *)application {
MAXLog(@"程序被杀死,applicationWillTerminate");
[[BMXClient sharedClient] disConnect];
fastSignInById:password:completion:
通过用户ID自动登录(要求之前成功登录过,登录速度较快)
- (void)fastSignInById:(long long)*uid* password:(NSString *)*password* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
通过用户ID自动登录(要求之前成功登录过,登录速度较快)
Declared In
BMXClient.h
fastSignInByName:password:completion:
通过用户名自动登录(要求之前成功登录过,登录速度较快)
- (void)fastSignInByName:(NSString *)*name* password:(NSString *)*password* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
通过用户名自动登录(要求之前成功登录过,登录速度较快)
Declared In
BMXClient.h
- (void)signByName:(NSString *)name password:(NSString *)password {
[[BMXClient sharedClient] fastSignInByName:name password:password completion:^(BMXError *error) {
initializeServerConfig:
获取app的服务器网络配置,在初始化SDK之后登陆之前调用,可以提前获取服务器配置加快登陆速度。
- (void)initializeServerConfig:(BOOL)*isLocal*
Parameters
isLocal
为true则使用本地缓存的dns配置,为false则从服务器获取最新的配置。
Discussion
获取app的服务器网络配置,在初始化SDK之后登陆之前调用,可以提前获取服务器配置加快登陆速度。
Declared In
BMXClient.h
networkDidChangedType:reconnect:
处理网络状态发送变化
- (void)networkDidChangedType:(BMXNetworkType)*type* reconnect:(BOOL)*reconnect*
Parameters
type
变化后的网络类型
reconnect
网络是否需要重连
Discussion
处理网络状态发送变化
Declared In
BMXClient.h
- (void)p_networkStatusDidChanged:(NSNotification *)notifiaction {
if ([notifiaction.name isEqualToString:@"disConnectionNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeNone reconnect:NO];
- (void)p_networkStatusDidChanged:(NSNotification *)notifiaction {
if ([notifiaction.name isEqualToString:@"disConnectionNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeNone reconnect:NO];
MAXLog(@"无网络");
} else if ([notifiaction.name isEqualToString:@"connectingIPhoneNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeMobile reconnect:YES];
- (void)p_networkStatusDidChanged:(NSNotification *)notifiaction {
if ([notifiaction.name isEqualToString:@"disConnectionNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeNone reconnect:NO];
MAXLog(@"无网络");
} else if ([notifiaction.name isEqualToString:@"connectingIPhoneNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeMobile reconnect:YES];
MAXLog(@"蜂窝");
} else if ([notifiaction.name isEqualToString:@"connectingInWifiNetworkNotifation"]) {
[[BMXClient sharedClient] networkDidChangedType:BMXNetworkTypeWifi reconnect:YES];
reconnect
强制重新连接
- (void)reconnect
Discussion
强制重新连接
Declared In
BMXClient.h
- (void)applicationWillEnterForeground:(UIApplication *)application {
// app从后台进入前台都会调用这个方法
// if (application.applicationIconBadgeNumber > 0) {
// application.applicationIconBadgeNumber = 0;
// }
IMAcount *accout = [IMAcountInfoStorage loadObject];
if (accout) {
[[BMXClient sharedClient] reconnect];
registerWithSDKConfig:
- (void)registerWithSDKConfig:(BMXSDKConfig *)*config*
} else {
config.enableDNS = YES;
}
} else {
config.enableDNS = YES;
}
config.verifyCertificate = NO;
[[BMXClient sharedClient] registerWithSDKConfig:config];
signInById:password:completion:
通过用户ID登录
- (void)signInById:(long long)*userId* password:(NSString *)*password* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
通过用户ID登录
Declared In
BMXClient.h
signInById:withToken:completion:
通过用户ID和token登录
- (void)signInById:(long long)*userId* withToken:(NSString *)*token* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
通过用户ID和token登录
Declared In
BMXClient.h
signInByName:password:completion:
通过用户名登录
- (void)signInByName:(NSString *)*userName* password:(NSString *)*password* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
通过用户名登录
Declared In
BMXClient.h
- (void)signByaccount:(IMAcount *)account {
[[BMXClient sharedClient] signInByName:account.userName password:account.password completion:^(BMXError * _Nonnull error) {
- (void)loginByName:(NSString *)userName
password:(NSString *)password {
[HQCustomToast showWating];
[[BMXClient sharedClient] signInByName:userName password:password completion:^(BMXError * _Nonnull error) {
- (void)loginAndEntryMainVCWithName:(NSString *)name password:(NSString *)password {
MAXLog(@"%@", [[BMXClient sharedClient] sdkConfig].hostConfig.restHost);
[HQCustomToast showWating];
[[BMXClient sharedClient] signInByName:name password:password completion:^(BMXError *error) {
- (void)registerLoginByName:(NSString *)name password:(NSString *)password {
[HQCustomToast showWating];
[[BMXClient sharedClient] signInByName:name password:password completion:^(BMXError *error) {
- (void)registerLoginBindByName:(NSString *)name password:(NSString *)password {
[HQCustomToast showWating];
[[BMXClient sharedClient] signInByName:name password:password completion:^(BMXError *error) {
signInStatus
获取当前的登录状态
- (BMXSignInStatus)signInStatus
Discussion
获取当前的登录状态
Declared In
BMXClient.h
signOutID:ignoreUnbindDevice:completion:
退出登录
- (void)signOutID:(NSInteger)*userID* ignoreUnbindDevice:(BOOL)*ignoreUnbindDevice* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
Discussion
退出登录
Declared In
BMXClient.h
- (void)logoutclick{
[HQCustomToast showWating];
[[BMXClient sharedClient] signOutID:(NSInteger)self.profile.userId ignoreUnbindDevice:NO completion:^(BMXError * _Nonnull error) {
[[BMXClient sharedClient] signOutID:(NSInteger)self.profile.userId ignoreUnbindDevice:NO completion:^(BMXError * _Nonnull error) {
if (!error) {
[HQCustomToast hideWating];
[self dealWithLogout];
} else {
[[BMXClient sharedClient] signOutID:(NSInteger)self.profile.userId ignoreUnbindDevice:YES completion:^(BMXError * _Nonnull error) {
signOutignoreUnbindDevice:completion:
- (void)signOutignoreUnbindDevice:(BOOL)*ignoreUnbindDevice* completion:(void ( ^ ) ( BMXError *error ))*aCompletionBlock*
signUpNewUser:password:completion:
注册新用户,username和password是必填参数
- (void)signUpNewUser:(NSString *)*userName* password:(NSString *)*password* completion:(void ( ^ ) ( BMXUserProfile *profile , BMXError *error ))*aCompletionBlock*
Parameters
userName
用户名
password
密码
aCompletionBlock
注册成功后从该函数处获取新注册用户的Profile信息,初始传入指向为空的shared_ptr对象即可。
Discussion
注册新用户,username和password是必填参数
Declared In
BMXClient.h
Example:
- (void)regiesterWithName:(NSString *)name password:(NSString *)password {
[[BMXClient sharedClient] signUpNewUser:name password:password completion:^(BMXUserProfile * _Nonnull profile, BMXError * _Nonnull error) {
- (void)registerAndBindPhoneUserName:(NSString *)userName
password:(NSString *)password {
// 注册
[[BMXClient sharedClient] signUpNewUser:userName password:password completion:^(BMXUserProfile * _Nonnull profile, BMXError * _Nonnull error) {
- (void)regiesterAndBindWechatWithName:(NSString *)name
password:(NSString *)password {
// 注册
[[BMXClient sharedClient] signUpNewUser:name password:password completion:^(BMXUserProfile * _Nonnull profile, BMXError * _Nonnull error) {