Initial commit
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
//
|
||||
// IfishUserDataUnity.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 17/4/7.
|
||||
// Copyright © 2017年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IfishUserDataUnity.h"
|
||||
#import "NTESLoginManager.h"
|
||||
#import "SVProgressHUD.h"
|
||||
#import "NTESService.h"
|
||||
#import "IfishMianTabViewController.h"
|
||||
#import "IfishUserDefaultHelper.h"
|
||||
#import "NSObject+LBLaunchImage.h"
|
||||
#import "IfishLoadingWebViewController.h"
|
||||
#import "IfishADTimerViewController.h"
|
||||
@implementation IfishUserDataUnity
|
||||
|
||||
+(IfishUserDataUnity*)shareDataInstance
|
||||
{
|
||||
static IfishUserDataUnity*instance=nil;
|
||||
static dispatch_once_t predicate;
|
||||
dispatch_once(&predicate, ^{
|
||||
instance=[[[self class]alloc]init];
|
||||
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
-(void)userloginValidationSuccsess:(NSDictionary *)dataDic phoneNumber:(NSString *)phoneNumber passward:(NSString *)password
|
||||
|
||||
{
|
||||
|
||||
NSDictionary *userDic=dataDic[@"userInfo"];
|
||||
UserModel *model=[[UserModel alloc] initWithDict:userDic];
|
||||
[[DataCenter defaultDtacenter]setValue:model forKey:@"UserLogIn"];
|
||||
|
||||
//金币任务等级
|
||||
NSDictionary *userAssetDic=dataDic[@"userAsset"];
|
||||
IfishUserAsset *userAsset =[[IfishUserAsset alloc] initWithDict:userAssetDic];
|
||||
[[DataCenter defaultDtacenter]setValue:userAsset forKey:@"IfishUserAsset"];
|
||||
|
||||
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||||
|
||||
[userdefult setObject:password forKey:@"password"];
|
||||
[userdefult setObject:phoneNumber forKey:@"name"];
|
||||
[userdefult setObject:@"0" forKey:@"isExit"];
|
||||
[userdefult setObject:model.userId forKey:@"userId"];
|
||||
|
||||
if ([model.userSex isEqual:[NSNull null]] || model.userSex ==nil) {
|
||||
model.userSex=@"";
|
||||
}
|
||||
|
||||
[userdefult setObject:model.userSex forKey:@"userSex"];
|
||||
[userdefult synchronize];
|
||||
|
||||
|
||||
NSLog(@"userDic:%@",userDic);
|
||||
NSLog(@"登录成功");
|
||||
//登陆云信
|
||||
NSString *acount = [NSString stringWithFormat:@"%@",model.userId];
|
||||
[self doLoginWithAccount:acount addToken:model.neteaseToken];
|
||||
[self setAppTabRoot];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -登陆云信服务器
|
||||
- (void)doLoginWithAccount:(NSString *)acount addToken:(NSString *)token
|
||||
{
|
||||
|
||||
NSString *loginAccount = acount;
|
||||
NSString *loginToken = token;
|
||||
|
||||
//NIM SDK 只提供消息通道,并不依赖用户业务逻辑,开发者需要为每个APP用户指定一个NIM帐号,NIM只负责验证NIM的帐号即可(在服务器端集成)
|
||||
//用户APP的帐号体系和 NIM SDK 并没有直接关系
|
||||
//DEMO中使用 username 作为 NIM 的account ,md5(password) 作为 token
|
||||
//开发者需要根据自己的实际情况配置自身用户系统和 NIM 用户系统的关系
|
||||
|
||||
|
||||
[[[NIMSDK sharedSDK] loginManager] login:loginAccount
|
||||
token:loginToken
|
||||
completion:^(NSError *error) {
|
||||
[SVProgressHUD dismiss];
|
||||
if (error == nil)
|
||||
{
|
||||
LoginData *sdkData = [[LoginData alloc] init];
|
||||
sdkData.account = loginAccount;
|
||||
sdkData.token = loginToken;
|
||||
[[NTESLoginManager sharedManager] setCurrentLoginData:sdkData];
|
||||
|
||||
[[NTESServiceManager sharedManager] start];
|
||||
//NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
|
||||
// NSLog(@"count%d",count);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:IFISHIMLOGINSUCSESS object:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *toast = [NSString stringWithFormat:@"登录失败 code: %zd",error.code];
|
||||
[[UIApplication sharedApplication].keyWindow makeToast:toast ];
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - 自动登录
|
||||
|
||||
-(void)userAutologinSuccsess:(NSDictionary *)dataDic
|
||||
{
|
||||
NSDictionary *userDic=dataDic[@"userInfo"];
|
||||
UserModel *model=[[UserModel alloc] initWithDict:userDic];
|
||||
[[DataCenter defaultDtacenter]setValue:model forKey:@"UserLogIn"];
|
||||
|
||||
//金币任务等级
|
||||
NSDictionary *userAssetDic=dataDic[@"userAsset"];
|
||||
IfishUserAsset *userAsset =[[IfishUserAsset alloc] initWithDict:userAssetDic];
|
||||
[[DataCenter defaultDtacenter]setValue:userAsset forKey:@"IfishUserAsset"];
|
||||
|
||||
//是否升级
|
||||
NSString *oldGradeNum = [IfishUserDefaultHelper getDefualtGradNum];
|
||||
NSString *gradeNum = [NSString stringWithFormat:@"%@",userAsset.gradeNum];
|
||||
if ([oldGradeNum intValue]<[gradeNum intValue]){
|
||||
[[IfishUserObsever sharedInstance] showLevelUpWith:gradeNum];
|
||||
[IfishUserDefaultHelper chageLevlelGrad:gradeNum];
|
||||
}
|
||||
|
||||
|
||||
//登陆云信 走自动登录
|
||||
LoginData *data = [[NTESLoginManager sharedManager] currentLoginData];
|
||||
NSString *account = [data account];
|
||||
NSString *token = [data token];
|
||||
|
||||
//如果有缓存用户名密码推荐使用自动登录
|
||||
if ([account length] && [token length])
|
||||
{
|
||||
//自动登录
|
||||
//非强制模式
|
||||
//[[[NIMSDK sharedSDK] loginManager] autoLogin:account
|
||||
// token:token];
|
||||
//这里我们使用强制模式 即不考虑安全登录 多设备同帐号登陆
|
||||
|
||||
NIMAutoLoginData * LoginData = [[NIMAutoLoginData alloc] init];
|
||||
LoginData.account = account;
|
||||
LoginData.token = token;
|
||||
//强制模式 强制模式下的自动登录,服务器将不检查当前登录设备是否为上一次登录设备,安全性较低。但相对的更加方便,适合 IM 仅作为辅助模块的 App
|
||||
|
||||
LoginData.forcedMode = YES;
|
||||
[[[NIMSDK sharedSDK] loginManager] autoLogin:LoginData];
|
||||
[[NTESServiceManager sharedManager] start];
|
||||
|
||||
}
|
||||
else
|
||||
{ //注册登录
|
||||
NSString *acount = [NSString stringWithFormat:@"%@",model.userId];
|
||||
[self doLoginWithAccount:acount addToken:model.neteaseToken];
|
||||
}
|
||||
|
||||
//[self startLounchImg];
|
||||
//完成登陆验证开始 广告页倒计时
|
||||
[self setAdViewVC];
|
||||
|
||||
}
|
||||
|
||||
-(void)setAdViewVC
|
||||
{
|
||||
IfishADTimerViewController *mianVC=[[IfishADTimerViewController alloc] init];
|
||||
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mianVC];
|
||||
[UIApplication sharedApplication].delegate.window.rootViewController=nav;
|
||||
|
||||
}
|
||||
-(void)startLounchImg{
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[NSObject makeLBLaunchImageAdView:^(LBLaunchImageAdView *imgAdView) {
|
||||
[[UIApplication sharedApplication].keyWindow addSubview:imgAdView];
|
||||
|
||||
//设置广告的类型
|
||||
imgAdView.getLBlaunchImageAdViewType(LogoAdType);
|
||||
//设置本地启动图片
|
||||
imgAdView.localAdImgName = @"Ifishlaunch_adView.jpg";
|
||||
//自定义跳过按钮
|
||||
imgAdView.skipBtn.backgroundColor = [UIColor blackColor];
|
||||
//各种点击事件的回调
|
||||
imgAdView.clickBlock = ^(clickType type){
|
||||
switch (type) {
|
||||
case clickAdType:{
|
||||
NSLog(@"点击广告回调");
|
||||
//TestViewController *vc = [[TestViewController alloc]init];
|
||||
//vc.view.backgroundColor = [UIColor whiteColor];
|
||||
//[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:vc animated:YES completion:^{
|
||||
|
||||
// }];
|
||||
IfishMianTabViewController *mianVC=[[IfishMianTabViewController alloc] init];
|
||||
[UIApplication sharedApplication].delegate.window.rootViewController=mianVC;
|
||||
IfishLoadingWebViewController *pushVC = [[IfishLoadingWebViewController alloc] init];
|
||||
pushVC.pushlink = IFISH_DEVCEITROURL;
|
||||
[mianVC.navigationController pushViewController:pushVC animated:YES];
|
||||
|
||||
}
|
||||
break;
|
||||
case skipAdType:
|
||||
{
|
||||
NSLog(@"点击跳过回调");
|
||||
[weakSelf setAppTabRoot];
|
||||
}
|
||||
|
||||
break;
|
||||
case overtimeAdType:
|
||||
|
||||
{
|
||||
|
||||
NSLog(@"倒计时完成后的回调");
|
||||
[weakSelf setAppTabRoot];
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
//设置根视图
|
||||
-(void)setAppTabRoot{
|
||||
|
||||
IfishMianTabViewController *mianVC=[[IfishMianTabViewController alloc] init];
|
||||
[UIApplication sharedApplication].delegate.window.rootViewController=mianVC;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user