[XMPP]iOS聊天软件学习笔记[二]
今天做的不是很多,主要做了登陆界面
开发时间:五天(工作时间)
开发工具:xcode6
开发平台:iOS8
XMPP框架:XMPPFramework
git clone https://github.com/robbiehanson/XMPPFramework.git
界面设计:使用StoryBoard
github地址:https://github.com/hjandyz/XMPP
现阶段的样子
1.自定义导航控制器,状态栏的模式改变在xcode5以后需要配置plist文件
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
plist 中 View controller-based status bar appearance 设置为 NO
2.使用单例的方法管理用户信息,下面是单例的宏
// .h
#define singleton_interface(class) + (instancetype)shared##class;
// .m
#define singleton_implementation(class) \
static class *_instance; \
\
+ (id)allocWithZone:(struct _NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
\
return _instance; \
} \
\
+ (instancetype)shared##class \
{ \
if (_instance == nil) { \
_instance = [[class alloc] init]; \
} \
\
return _instance; \
}
3.登陆的方法抽成一个夫类
- (void)login
{
//隐藏键盘
[self.view endEditing:YES];
//显示正在登录
[MBProgressHUD showMessage:@"正在登录..." toView:self.view];
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
__weak typeof (self) weekSelf = self;
[delegate xmppUserLogin:^(XMPPResultType type) {
[weekSelf handleResultTye:type];
}];
}
- (void)handleResultTye:(XMPPResultType)type
{
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
switch (type) {
case XMPPResultTypeLoginSuccess:
[self enterToMainPage];
break;
case XMPPResultTypeLoginFailure:
NSLog(@"登录失败");
[MBProgressHUD showError:@"用户名或密码错误" toView:self.view];
break;
case XMPPResultTypeNetErr:
[MBProgressHUD showError:@"网络不给力" toView:self.view];
break;
default:
break;
}
});
}
- (void)enterToMainPage
{
//更改为登录状态
[HJUserInfo sharedHJUserInfo].loginStatus = YES;
//把用户数据保存到沙盒
[[HJUserInfo sharedHJUserInfo] saveUserInfoToSanbox];
//隐藏模态窗口
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"登录成功");
//登录成功后到主界面
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// self.window.rootViewController = storyboard.instantiateInitialViewController;
self.view.window.rootViewController = storyboard.instantiateInitialViewController;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。