登錄及自動(dòng)登錄機(jī)制研究
首次登錄,調(diào)用登錄接口
之后登錄,判斷是否存在token【未過期】,調(diào)用自動(dòng)登錄接口
后臺,對token進(jìn)行控制,token在本地的有效期為七天
若用戶經(jīng)常登錄,后臺負(fù)責(zé)在合適的時(shí)機(jī)【即將過期】,自動(dòng)登錄的時(shí)候,更新本地token,保證經(jīng)常登錄的用戶身份不會過期
若身份過期,提示重新登錄
手勢密碼應(yīng)用場景及機(jī)制
在每次調(diào)用自動(dòng)登錄接口時(shí)候,如果有設(shè)置手勢密碼,則進(jìn)入手勢密碼界面輸入手勢,與系統(tǒng)保存的手勢密碼相同則登錄,多次輸入,不對,直接進(jìn)入登錄界面,手動(dòng)輸入密碼
【與QQ登錄機(jī)制一樣】
手勢密碼的原理
將九宮格中的九個(gè)圓形用1-9標(biāo)記,設(shè)置最少連四個(gè)點(diǎn),就是最少四位數(shù)
如果兩次手勢最后的數(shù)字都一樣就可以進(jìn)行本地化保存了
手勢的保存可以通過系統(tǒng)單例保存,如果手勢密碼在服務(wù)器也保存,換手機(jī)也可以使用手勢密碼了
[[NSUserDefaults standardUserDefaults] objectForKey:key];
引導(dǎo)頁機(jī)制
在應(yīng)用啟動(dòng)時(shí),判斷一個(gè)未存儲過的字段是否存在,不存在則進(jìn)入引導(dǎo)界面,并設(shè)置為根視圖,在引導(dǎo)視圖滾動(dòng)結(jié)束進(jìn)入登錄界面,并將登錄界面設(shè)置為根視圖,登錄成功,進(jìn)入主頁面,在將主頁面設(shè)置為根視圖
極光機(jī)制
針對用戶推送消息,針對手機(jī)客戶端推送消息
在應(yīng)用啟動(dòng)的時(shí)候,對極光進(jìn)行一些配置
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
if([UINavigationBar conformsToProtocol:@protocol(UIAppearanceContainer)]) {
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
// //保證導(dǎo)航欄顏色與設(shè)置的顏色值一樣
// [UINavigationBar appearance].translucent = NO;
// //去掉導(dǎo)航欄與視圖間的線
// [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
// [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:18], NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UINavigationBar appearance] setBarTintColor:naviBarAndButtonColor];
}
//極光部分
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
NSString *str = [[NSBundle mainBundle] pathForResource:@"PushConfig" ofType:@"plist"];
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:str];
[JPUSHService setupWithOption:launchOptions appKey:[dic objectForKey:@"APP_KEY"] channel:[dic objectForKey:@"CHANNEL"] apsForProduction:[[dic objectForKey:@"APS_FOR_PRODUCTION"] boolValue]];
[JPUSHService crashLogON];
[JPUSHService registrationID];
return YES;
}
登錄成功,設(shè)置別名
為安裝了應(yīng)用程序的用戶,取個(gè)別名來標(biāo)識。以后給該用戶 Push 消息時(shí),就可以用此別名來指定。
每個(gè)用戶只能指定一個(gè)別名。
同一個(gè)應(yīng)用程序內(nèi),對不同的用戶,建議取不同的別名。這樣,盡可能根據(jù)別名來唯一確定用戶。
標(biāo)簽 tag
為安裝了應(yīng)用程序的用戶,打上標(biāo)簽。其目的主要是方便開發(fā)者根據(jù)標(biāo)簽,來批量下發(fā) Push 消息。
可為每個(gè)用戶打多個(gè)標(biāo)簽。
-(void)loginSuccessed:(NSObject *)obj
{
/*設(shè)置極光推送的唯一標(biāo)識,與群體標(biāo)識*/
NSString *alias = [NSString stringWithFormat:@"NT_%@",g_loginUser.userId];
[JPUSHService setTags:nil alias:alias callbackSelector:@selector(tagsAliasCallback:tags:alias:) target:self];
//判斷是否是通過別的app打開我們的應(yīng)用
//登錄(包括自動(dòng)登錄)成功,判斷是否是通過外部應(yīng)用登錄(crm調(diào)用聊天)
if (_schemeUserDic) {
//判斷登錄身份[該數(shù)組中的第一個(gè)數(shù)據(jù)是本人工號,第二個(gè)是要找的人工號]
if ([g_loginUser.userName isEqualToString:_schemeUserDic[@"userName"]]) {
[self showMainUIWithIndex:0];
[g_notify postNotificationName:@"usernameArrNoti" object:nil userInfo:_schemeUserDic];
}else {
[self goLoginVC];
}
}else {
[self showMainUIWithIndex:1];
}
[NTDatabaseHelper refreshDatabase];
NTLastMessage *systemMsg = [[NTLastMessage alloc]init];
[systemMsg createNoticCenter];
}
退出取消用戶的極光別名,保證退出后,不再收到有關(guān)用戶的別名
[JPUSHService setTags:nil alias:@"" callbackSelector:@selector(tagsAliasCallback:tags:alias:) target:self];
版本更新機(jī)制
1.在應(yīng)用啟動(dòng)的時(shí)候,調(diào)用配置文件接口,獲取到我們應(yīng)用所有需要的接口
2.調(diào)用成功后,開始調(diào)用[檢查更新]接口
獲取配置文件接口
#pragma mark -- getConfigInfo
-(void)configInfo
{
[NTServiceShell ConfigInfo:nil completion:^(NSDictionary *response) {
[g_config didReceive:response];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self checkUpdate : nil];
});
} withError:^(NSString *errorMsg) {
[HUDNotificationCenter showMessage:[errorMsg description] hideAfter:2.0f];
}];
}
檢查更新接口
#pragma mark - checkUpdate
-(void)checkUpdate:(NSObject *)obj
{
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
//請求服務(wù)器檢查版本
NSDictionary *dic = @{@"os":@"ios", @"version":appVersion};
[NTServiceShell CheckUpdateInfo:dic completion:^(NSDictionary *response) {
NSString *ret = nil;
NSString *newNote = @"是否更新?";
NSString *titleStr = @"發(fā)現(xiàn)新版本";
if (response != nil) {
if (response[@"ret"]) {
ret = response[@"ret"];
newNote = response[@"newNote"];
titleStr = [NSString stringWithFormat:@"%@%@",titleStr,response[@"newVer"]];
}
}
if ([ret isEqualToString:@"0"]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *avUpdate = [[UIAlertView alloc] initWithTitle:titleStr
message:newNote
delegate:self
cancelButtonTitle:@"立刻訪問"
otherButtonTitles:@"下次再說", nil];
avUpdate.tag = 100;
[avUpdate show];
});
}
if ([ret isEqualToString:@"-1"]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *avUpdate = [[UIAlertView alloc] initWithTitle:titleStr
message:newNote
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"立刻訪問", nil];
avUpdate.tag = 101;
[avUpdate show];
});
}
} withError:^(NSString *error) {
}];
}