1.導(dǎo)入 LoginSDK 并進(jìn)行相關(guān)配置
導(dǎo)入SDK到我們的App工程后吏够,我們要對(duì)其進(jìn)行相應(yīng)的配置悼沈。首先我們要對(duì)?Framework Search Paths?進(jìn)行配置法挨,也就是說(shuō)告訴編譯器我們的第三方SDK所在的位置筷狼。
配置完路徑后寝优,接下來(lái)我們要在 Other Linker Flags 添加上 -Objc 和 -all_load 選項(xiàng);
2. LoginSDK 的使用
配置完畢后,接下來(lái)就是在我們App中使用該 LoginSDK 了。下方代碼就是我們上述 LoginSDK 的使用方式,首先獲取單例齿税,然后檢查是否登錄,登錄成功后根據(jù)Block回調(diào)跳轉(zhuǎn)到首頁(yè)炊豪,如果未登錄凌箕,就通過(guò)LoginAPI獲取登錄頁(yè)面進(jìn)行登錄;
3.使用Demo
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? _loginAPI = [LoginAPI shareManager];? ? ? ? //獲取LoginAPI單例
}
- (IBAction)tapLogin: (id)sender {
? ? [self checkHaveLogin:YES];
}
//檢查是否已經(jīng)登錄
- (void)checkHaveLogin: (BOOL)isTapButton {
? ? if (_loginAPI != nil) {
? ? ? ? __weak typeof (self) weak_self = self;
? ? ? ? [_loginAPI checkHaveLogin:^(NSString *token) {
? ? ? ? ? ? [weak_self presentMainViewControllerWithText:token];? ? //二次登錄,成功后直接進(jìn)入首頁(yè)
? ? ? ? } noAccountBlock:^{
? ? ? ? ? ? if (isTapButton) {
? ? ? ? ? ? ? ? [weak_self presentLoginViewController];? ? ? ? ? ? //首次登錄词渤,獲取登錄頁(yè)面牵舱,進(jìn)行登錄
? ? ? ? ? ? }
? ? ? ? }];
? ? }
}
//通過(guò)loginAPI獲取登錄頁(yè)面,并對(duì)登錄成功后的事件進(jìn)行處理
- (void)presentLoginViewController {
? ? __weak typeof (self) weak_self = self;
? ? UIViewController *vc = [_loginAPI getLoginViewController:^(NSString *token) {
? ? ? ? [weak_self presentMainViewControllerWithText:token];
? ? }];
? ? vc.modalPresentationStyle=UIModalPresentationOverFullScreen;
? ? [self presentViewController:vc animated:YES completion:^{}];
}
-(void)viewDidAppear:(BOOL)animated {
? ? //[self checkHaveLogin:NO];
}
- (void)presentMainViewControllerWithText: (NSString *)text {
? ? UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
? ? MainViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
? ? [vc setTipLableText:[NSString stringWithFormat:@"登錄成功: %@", text]];
? ? [self presentViewController:vc animated:NO completion:^{
? ? }];
}