創(chuàng)藍(lán)閃驗一鍵登錄

221閃驗集成文檔-簡版

一亩歹、創(chuàng)建應(yīng)用

**提示:一個應(yīng)用對應(yīng)一個appid,多個應(yīng)用(不同bundleID)需在閃驗平臺創(chuàng)建多個應(yīng)用以對應(yīng)多個appid
**
應(yīng)用的創(chuàng)建流程及APPID/APPKEY的獲取,請查看「賬號創(chuàng)建」文檔

二惊窖、集成方式

1.通過CocoaPods自動集成

在工程的Podfile里面添加以下代碼:以下示例pod 版本僅供參考,請按需選擇或選擇最新版本

pod 'CL_ShanYanSDK', '2.2.0.5'

注意:
在podfile中保存并執(zhí)行pod install --no-repo-update,然后用后綴為.xcworkspace的文件打開工程。
命令行下執(zhí)行pod search CL_ShanYanSDK,如顯版本不是最新版漫雷,或者pod install導(dǎo)入的版本不是最新版,則先執(zhí)行pod repo update操作更新本地repo的內(nèi)容
關(guān)于CocoaPods的更多信息請查看 CocoaPods官方網(wǎng)站鳍咱。

2. 手動集成

2.1 導(dǎo)入framework

將閃驗SDK壓縮包中framework文件夾下所有資源添加到工程中(注意勾選Copy items if needed)

image

2.2 Xcode配置

  • OtherLinkerFlags中 添加-ObjC****:xcode->BuildSetting->Other Linker Flags 添加 -ObjC
    image
  • 添加libc++.1.tbd: 在xcode->General->Linked Frameworks and Libraries中點擊 + 降盹,搜索并選擇添加 libc++.1.tbd
    image

3. Swift工程額外配置

  • 在xcode->BuildSetting->Other Linker Flags 添加-force_load


    image
  • 在-force_load下方添加CL_ShanYanSDK.framework/CL_ShanYanSDK所在路徑,具體操作可以將CL_ShanYanSDK.framework拖入空欄谤辜,在尾部拼接靜態(tài)庫名稱CL_ShanYanSDK蓄坏,將前綴絕對地址改成相對地址(SRCROOT)价捧,最終為 "(SRCROOT)/.../CL_ShanYanSDK.framework/CL_ShanYanSDK"形式
    image

三、SDK使用說明

1.初始化

  • 導(dǎo)入閃驗SDK頭文件 #import <CL_ShanYanSDK/CL_ShanYanSDK.h>
  • 在AppDelegate中的 didFinishLaunchingWithOptions方法中添加初始化代碼

注意:需要填入閃驗控制臺上的appid 和 appkey涡戳,同時項目工程需要匹配控制臺上的bundleId

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // 需要填入閃驗控制臺上的appid 和 appkey
    [CLShanYanSDKManager initWithAppId:cl_SDK_APPID AppKey:cl_SDK_APPKEY complete:^(CLCompleteResult * _Nonnull completeResult) {
        if (completeResult.error) {
            NSLog(@"初始化失敗");
        } else {
            NSLog(@"初始化成功");
        }
    }];
}

2.預(yù)取號

建議進(jìn)入頁面時在viewDidLoad中進(jìn)行預(yù)取號操作

- (void)viewDidLoad {
    [super viewDidLoad];
    // 預(yù)取號
    [CLShanYanSDKManager preGetPhonenumber:nil];
}

3.拉起授權(quán)頁

3.1 授權(quán)頁UI設(shè)置

// 控件元素設(shè)置
CLUIConfigure * baseUIConfigure = [[CLUIConfigure alloc] init];

// self 為拉起授權(quán)頁時的當(dāng)前頁面控制器
baseUIConfigure.viewController = self;

baseUIConfigure.clNavigationBackgroundClear = @(YES);
baseUIConfigure.clNavigationBottomLineHidden = @(YES);
baseUIConfigure.clNavigationBackBtnImage = [UIImage imageNamed:@"close-white"];
baseUIConfigure.clNavigationBarStyle = @(UIBarStyleBlack);


//LOGO
baseUIConfigure.clLogoImage = [UIImage imageNamed:@"logo_shanyan_text"];
baseUIConfigure.clLogoCornerRadius = @(10);


//PhoneNumber
baseUIConfigure.clPhoneNumberColor = UIColor.blackColor;
baseUIConfigure.clPhoneNumberFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:20.0*screenScale];

//LoginBtn
baseUIConfigure.clLoginBtnText = @"本機號一鍵登錄";
baseUIConfigure.clLoginBtnTextFont = [UIFont systemFontOfSize:15*screenScale];
baseUIConfigure.clLoginBtnBgColor = [UIColor colorWithRed:0.2 green:0.8 blue:0.2 alpha:1];
baseUIConfigure.clLoginBtnCornerRadius = @(10*screenScale);

//Privacy
baseUIConfigure.clAppPrivacyFirst = @[@"閃驗用戶協(xié)議",[NSURL URLWithString:@"https://www.baidu.com"]];
baseUIConfigure.clAppPrivacySecond = @[@"隱私政策",[NSURL URLWithString:@"https://www.sina.com"]];
baseUIConfigure.clAppPrivacyColor = @[[UIColor lightGrayColor],[UIColor greenColor]];
baseUIConfigure.clAppPrivacyTextAlignment = @(NSTextAlignmentCenter);
baseUIConfigure.clAppPrivacyTextFont = [UIFont systemFontOfSize:11*screenScale];

//隱私協(xié)議頁
baseUIConfigure.clAppPrivacyWebBackBtnImage = [UIImage imageNamed:@"title_back"];
NSMutableAttributedString * att0 = [[NSMutableAttributedString alloc]initWithString:@"隱私" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor blueColor]}];
NSMutableAttributedString * att1 = [[NSMutableAttributedString alloc]initWithString:@"條款" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor orangeColor]}];
[att0 appendAttributedString:att1];
baseUIConfigure.clAppPrivacyWebAttributesTitle = att0;

//CheckBox
baseUIConfigure.clCheckBoxHidden = @(NO);
baseUIConfigure.clCheckBoxValue = @(NO);
baseUIConfigure.clCheckBoxSize = [NSValue valueWithCGSize:CGSizeMake(30*screenScale, 30*screenScale)];
baseUIConfigure.clCheckBoxImageEdgeInsets = [NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(2*screenScale, 10*screenScale, 13*screenScale, 5*screenScale)];
baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyCenterY = @(YES);
baseUIConfigure.clCheckBoxCheckedImage = [UIImage imageNamed:@"checkBoxSEL"];
baseUIConfigure.clCheckBoxUncheckedImage = [UIImage imageNamed:@"checkBoxNor"];

//Slogan
baseUIConfigure.clSloganTextColor = UIColor.lightGrayColor;
baseUIConfigure.clSloganTextFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:11.0*screenScale];
baseUIConfigure.clSlogaTextAlignment = @(NSTextAlignmentCenter);

// 控件布局設(shè)置
CGFloat screenWidth_Portrait;
CGFloat screenHeight_Portrait;
CGFloat screenWidth_Landscape;
CGFloat screenHeight_Landscape;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    screenWidth_Portrait = UIScreen.mainScreen.bounds.size.width;
    screenHeight_Portrait = UIScreen.mainScreen.bounds.size.height;
    screenWidth_Landscape = UIScreen.mainScreen.bounds.size.height;
    screenHeight_Landscape = UIScreen.mainScreen.bounds.size.width;
}else{
    screenWidth_Portrait = UIScreen.mainScreen.bounds.size.height;
    screenHeight_Portrait = UIScreen.mainScreen.bounds.size.width;
    screenWidth_Landscape = UIScreen.mainScreen.bounds.size.width;
    screenHeight_Landscape = UIScreen.mainScreen.bounds.size.height;
}

CGFloat screenScale = [UIScreen mainScreen].bounds.size.width/375.0;
if (screenScale > 1) {
    screenScale = 1;
}

//layout 布局
//布局-豎屏
CLOrientationLayOut * clOrientationLayOutPortrait = [CLOrientationLayOut new];

clOrientationLayOutPortrait.clLayoutPhoneCenterY = @(0*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneLeft = @(50*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneRight = @(-50*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneHeight = @(20*screenScale);

clOrientationLayOutPortrait.clLayoutLogoWidth = @(100*screenScale);
clOrientationLayOutPortrait.clLayoutLogoHeight = @(100*screenScale);
clOrientationLayOutPortrait.clLayoutLogoCenterX = @(0);
clOrientationLayOutPortrait.clLayoutLogoCenterY = @(-SCREEN_HEIGHT*0.25);

clOrientationLayOutPortrait.clLayoutLoginBtnCenterY= @(clOrientationLayOutPortrait.clLayoutPhoneCenterY.floatValue + clOrientationLayOutPortrait.clLayoutPhoneHeight.floatValue*0.5*screenScale + 20*screenScale + 15*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnHeight = @(30*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnLeft = @(70*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnRight = @(-70*screenScale);

clOrientationLayOutPortrait.clLayoutAppPrivacyLeft = @(40*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyRight = @(-40*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyBottom = @(0*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyHeight = @(45*screenScale);

clOrientationLayOutPortrait.clLayoutSloganLeft = @(0);
clOrientationLayOutPortrait.clLayoutSloganRight = @(0);
clOrientationLayOutPortrait.clLayoutSloganHeight = @(15*screenScale);
clOrientationLayOutPortrait.clLayoutSloganBottom = @(clOrientationLayOutPortrait.clLayoutAppPrivacyBottom.floatValue - clOrientationLayOutPortrait.clLayoutAppPrivacyHeight.floatValue);
baseUIConfigure.clOrientationLayOutPortrait = clOrientationLayOutPortrait;

// 拉起授權(quán)頁時將baseUIConfigure參數(shù)傳入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
        dispatch_async(dispatch_get_main_queue(), ^{
            // 隱藏loading操作
            ...
        });
        if (completeResult.error) {
            NSLog(@"授權(quán)頁拉起失敗");
        }else{
            NSLog(@"授權(quán)頁拉起成功");
        }
 } oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
        if (completeResult.error) {
            NSLog(@"一鍵登錄失敗");
        }else{
            NSLog(@"一鍵登錄成功---進(jìn)行置換手機號操作");
            
            // 置換手機號操作
            ...
        }
    }
];


3.2 自定義控件

__weak typeof(self) weakSelf = self;
baseUIConfigure.customAreaView = ^(UIView * _Nonnull customAreaView) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    UIImageView * bg0 = [UIImageView new];
    [customAreaView addSubview:bg0];
    UIImageView * bg = [[UIImageView alloc]init];
    [customAreaView addSubview:bg];

    UIButton * weChat = [[UIButton alloc]init];
    [weChat setBackgroundImage:[UIImage imageNamed:@"微信"] forState:(UIControlStateNormal)];
    [customAreaView addSubview:weChat];
    UIButton * qq = [[UIButton alloc]init];
    [qq setBackgroundImage:[UIImage imageNamed:@"qq"] forState:(UIControlStateNormal)];
    [customAreaView addSubview:qq];

    UIButton * weibo = [[UIButton alloc]init];
    [weibo setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:(UIControlStateNormal)];
    [customAreaView addSubview:weibo];

    //布局
    [strongSelf setSeylt2Contrains:bg0 bg:bg wx:weChat qq:qq webo:weibo customView:customAreaView];

    //屏幕旋轉(zhuǎn)通知
    strongSelf-> _notifObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidChangeStatusBarFrameNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        [strongSelf setSeylt2Contrains:bg0 bg:bg wx:weChat qq:qq webo:weibo customView:customAreaView];
    }];
};

3.3 自定義loading

// 自定義loading
baseUIConfigure.loadingView = ^(UIView * _Nonnull containerView) {
    UIImage *image = [YYImage imageNamed:@"KungFuPanda.gif"];
    UIImageView *imageBackground = [[YYAnimatedImageView alloc] initWithImage:image];
    [containerView addSubview:imageBackground];
    imageBackground.layer.cornerRadius = 40;
    imageBackground.layer.masksToBounds = YES;

    [imageBackground mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 80));
        make.center.mas_equalTo(0);
    }];
};

4.拉起授權(quán)頁

// 拉起授權(quán)頁時將baseUIConfigure參數(shù)傳入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
        dispatch_async(dispatch_get_main_queue(), ^{
            // 隱藏loading操作
            ...
        });
        if (completeResult.error) {
            NSLog(@"授權(quán)頁拉起失敗");
        }else{
            NSLog(@"授權(quán)頁拉起成功");
        }
 } oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
        if (completeResult.error) {
            NSLog(@"一鍵登錄失敗");
        }else{
            NSLog(@"一鍵登錄成功---進(jìn)行置換手機號操作");
            
            // 置換手機號操作
            ...
        }
    }
];

5.獲取置換手機號

[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
    ...
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
    if (completeResult.error) {
        ...
    }else{
        //SDK成功獲取到Token
        NSString * telecom = [completeResult.data valueForKey:@"telecom"];
        //urlStr:用戶后臺對接閃驗后臺后配置的API结蟋,以下為Demo提供的調(diào)試API及調(diào)用示例,在調(diào)試階段可暫時調(diào)用此API渔彰,也可用此API驗證后臺API是否正確配置
        NSString * urlStr = nil;
        if ([telecom isEqualToString:@"CMCC"]) {
          urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-m"];
        }else if ([telecom isEqualToString:@"CUCC"]) {
          urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-u"];
        }else if ([telecom isEqualToString:@"CTCC"]) {
          urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-t"];
        }else{
          //失敗
          return;
        }
        if (urlStr) {
          NSLog(@"tokenParamr:%@",completeResult.data);
          [NetWorkManager POST_url:urlStr withParameter:completeResult.data complete:^(NSDictionary * _Nonnull responseObject, NSError * _Nonnull error) {
              if (error) {
                  NSLog(@"置換手機號出錯:%@",error);
              }else{
                  NSInteger code = [[responseObject valueForKey:@"code"] integerValue];
                  if (code == 200000) {
                      NSString * mobileName = responseObject[@"data"][@"mobileName"];
                      // decryptUseDESKey:解密方法詳情見demo
                      NSString * mobileCode = [mobileName decryptUseDESKey:cl_SDK_APPKEY];
                      NSLog(@"免密登錄成功,手機號:%@",mobileCode);
                      
                      // 成功拿到手機號后嵌屎,關(guān)閉授權(quán)頁
                      [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:nil];
                  } else {
                      NSLog(@"免密登錄失敗:%@",responseObject);
                  }
              }
          }];
        }
    }
}];

6.關(guān)閉授權(quán)頁

注意:授權(quán)頁面未拉起的情況調(diào)用該方法無效并且無回調(diào)

// 
[CLShanYanSDKManager finishAuthControllerCompletion:^{
    // 關(guān)閉授權(quán)頁后其他操作--該回調(diào)已切換為主線程
}];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市恍涂,隨后出現(xiàn)的幾起案子宝惰,更是在濱河造成了極大的恐慌,老刑警劉巖乳丰,帶你破解...
    沈念sama閱讀 216,324評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件掌测,死亡現(xiàn)場離奇詭異,居然都是意外死亡产园,警方通過查閱死者的電腦和手機汞斧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,356評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來什燕,“玉大人粘勒,你說我怎么就攤上這事∈杭矗” “怎么了庙睡?”我有些...
    開封第一講書人閱讀 162,328評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長技俐。 經(jīng)常有香客問我乘陪,道長,這世上最難降的妖魔是什么雕擂? 我笑而不...
    開封第一講書人閱讀 58,147評論 1 292
  • 正文 為了忘掉前任啡邑,我火速辦了婚禮,結(jié)果婚禮上井赌,老公的妹妹穿的比我還像新娘谤逼。我一直安慰自己,他們只是感情好仇穗,可當(dāng)我...
    茶點故事閱讀 67,160評論 6 388
  • 文/花漫 我一把揭開白布流部。 她就那樣靜靜地躺著,像睡著了一般纹坐。 火紅的嫁衣襯著肌膚如雪枝冀。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,115評論 1 296
  • 那天,我揣著相機與錄音宾茂,去河邊找鬼瓷马。 笑死,一個胖子當(dāng)著我的面吹牛跨晴,可吹牛的內(nèi)容都是我干的欧聘。 我是一名探鬼主播,決...
    沈念sama閱讀 40,025評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼端盆,長吁一口氣:“原來是場噩夢啊……” “哼怀骤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起焕妙,我...
    開封第一講書人閱讀 38,867評論 0 274
  • 序言:老撾萬榮一對情侶失蹤蒋伦,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后焚鹊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體痕届,經(jīng)...
    沈念sama閱讀 45,307評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,528評論 2 332
  • 正文 我和宋清朗相戀三年末患,在試婚紗的時候發(fā)現(xiàn)自己被綠了研叫。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,688評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡璧针,死狀恐怖嚷炉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情探橱,我是刑警寧澤申屹,帶...
    沈念sama閱讀 35,409評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站隧膏,受9級特大地震影響哗讥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜胞枕,卻給世界環(huán)境...
    茶點故事閱讀 41,001評論 3 325
  • 文/蒙蒙 一忌栅、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧曲稼,春花似錦、人聲如沸湖员。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,657評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽娘摔。三九已至窄坦,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背鸭津。 一陣腳步聲響...
    開封第一講書人閱讀 32,811評論 1 268
  • 我被黑心中介騙來泰國打工彤侍, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人逆趋。 一個月前我還...
    沈念sama閱讀 47,685評論 2 368
  • 正文 我出身青樓盏阶,卻偏偏與公主長得像,于是被迫代替她去往敵國和親闻书。 傳聞我的和親對象是個殘疾皇子名斟,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,573評論 2 353

推薦閱讀更多精彩內(nèi)容

  • CocoaPods操作手冊 本文檔介紹了啥? 為什么要使用CocoaPods魄眉? 如何安裝CocoaPods砰盐? Po...
    風(fēng)小鉆閱讀 7,556評論 1 10
  • 最近在學(xué)習(xí)vue.js的時候發(fā)現(xiàn),vue的組件化的思想對于編寫代碼是一個非常有用的事情坑律。 首先為什么需要組件化岩梳? ...
    拂曉的云閱讀 7,168評論 6 23
  • 使用CocoaPods也有很長一段時間了,最近幾個月的時間里也主導(dǎo)了公司私有Pods的創(chuàng)建和使用晃择。在此期間踩過了不...
    Code_Ninja閱讀 115,451評論 12 185
  • 還記得陳奕迅的那首《最佳損友》嗎藕各?里面唱到:“為何舊知己在最后池摧,變不到老友〖た觯”聽他唱來作彤,老友一詞似乎比普通朋友有著...
    港漂圈閱讀 1,068評論 0 1
  • 寫了幾百字,刪除幾百字乌逐;再寫竭讳,再刪;最后只剩一兩百字浙踢,緊接著就是長達(dá)近一小時的撰白绢慢,思維如同一口干枯的井,舀不出一...
    蟲鳴吹晚風(fēng)閱讀 324評論 0 0