夢網(wǎng)統(tǒng)一認證SDK(iOS)接口文檔
1.初始化SDK
接口說明
- (void)initWithAppId:(NSNumber *)appId appKey:(NSString*_Nonnull)appKey;
本方法用于發(fā)起初始化一鍵免密登錄(或本機號碼校驗)能力,SDK完成網(wǎng)絡請求并根據(jù)運營商類型自動選擇配置信息。應用使用SDK功能時首先調(diào)用該方法。
接口參數(shù)
| 參數(shù) |
類型 |
說明 |
| appId |
int |
應用注冊的夢網(wǎng)id |
| appkey |
String |
應用注冊的appkey |
2.一鍵登錄預取號
接口說明
- (void)getAccessCodeFinishBlock:(MWReturnBlock _Nonnull )complete;
預取號碼信息,獲取AccessCode。建議在APP登錄頁初始化時調(diào)用,提高后續(xù)授權(quán)頁的打開速度。不要在APP啟動初始化時調(diào)用,避免接口調(diào)用資源浪費。
接口參數(shù)
| 參數(shù) |
類型 |
說明 |
| complete |
MWReturnBlock |
一鍵登錄預取號結(jié)果的回調(diào) |
3.一鍵登錄喚起授權(quán)頁并獲取token
接口說明
- (void)authLoginWithBlock:(MWReturnBlock _Nonnull )complete;
喚起一鍵登錄授權(quán)頁,在用戶授權(quán)后獲取一鍵登錄的token。為了提高安全性,本SDK不直接提供獲取手機號明文的功能。應用服務端可以使用此token訪問夢網(wǎng)服務端接口,獲取具體的手機號碼信息。
接口參數(shù)
| 參數(shù) |
類型 |
說明 |
| complete |
MWReturnBlock |
一鍵登錄獲取一鍵登錄的token |
4.獲取本機號碼校驗token
接口說明
- (void)requestPhoneTokenWithBlock:(MWReturnBlock _Nonnull)complete;
返回token,用于手機號碼校驗。為了提高安全性,本SDK不直接提供號碼校驗功能,應用服務端可以使用此token和待校驗的手機號碼訪問夢網(wǎng)服務端接口,確定待校驗號碼是否為本機號碼。
接口參數(shù)
| 參數(shù) |
類型 |
說明 |
| complete |
MWReturnBlock |
獲取本機號碼校驗token的回調(diào) |
5.授權(quán)頁UI個性化定制
接口說明
[[MWUniLoginSDK shareInstance] setAuthViewModel:self.authViewModel];
根據(jù)應用UI風格可以個性化定制授權(quán)頁UI顯示效果,以保持應用統(tǒng)一的風格。
接口參數(shù)
| 參數(shù) |
類型 |
說明 |
| AuthViewModel |
UACustomModel |
主題配置Model,通過配置里面的參數(shù)來自定義授權(quán)界面 |
AuthViewModel配置參數(shù)說明
5.1.導航欄
| 方法 |
參數(shù)類型 |
說明 |
| authViewBlock |
Block |
在authViewBlock返回的customView中添加自定義導航欄視圖 |
| webNavColor |
UIColor |
web協(xié)議界面導航標題欄顏色 |
| webNavTitleAttrs |
NSDictionary |
web協(xié)議界面導航標題字體屬性設置 默認值:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:16]} |
-
authViewBlock示例
__weak typeof(self) weakSelf = self;
//自定義視圖在這里面添加到customView上
_authViewModel.authViewBlock = ^(UIView *customView, CGRect numberFrame, CGRect loginBtnFrame, CGRect checkBoxFrame, CGRect privacyFrame) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf addSubviewsIntoCustomView:customView withNumberFrame:numberFrame loginBtnFrame:loginBtnFrame checkBoxFrame:checkBoxFrame privacyFrame:privacyFrame];
};
//給授權(quán)界面添加自定義UI
- (void)addSubviewsIntoCustomView:(UIView *)customView withNumberFrame:(CGRect)numberFrame loginBtnFrame:(CGRect)loginBtnFrame checkBoxFrame:(CGRect)checkBoxFrame privacyFrame:(CGRect)privacyFrame
{
CGFloat top = Height_StatusBar;
CGFloat height = Height_NavBar;
if (_authViewModel.authWindow) {
top = 0;
height = 44;
}
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
backButton.frame = CGRectMake(10, top, 40, 40);
backButton.tintColor = [UIColor whiteColor];
[backButton setImage:[UIImage imageNamed:@"titlebar_icon_back"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, customView.frame.size.width, height)];
navView.backgroundColor = ThemeColor;
[customView addSubview:navView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, top, customView.frame.size.width, 44)];
titleLabel.font = [UIFont systemFontOfSize:17];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"一鍵登錄";
[navView addSubview:titleLabel];
[navView addSubview:backButton];
}
5.2.號碼欄
| 方法 |
參數(shù)類型 |
說明 |
| numberOffsetX |
NSNumber |
號碼欄X偏移量 |
| setNumFieldOffsetY |
NSNumber |
號碼欄Y偏移量 |
| setNumFieldOffsetY_B |
NSNumber |
號碼欄Y偏移量(基于底部) |
5.3.登錄按鈕
| 方法 |
參數(shù)類型 |
說明 |
| logBtnText |
NSAttributedString |
設置登錄按鈕富文本內(nèi)容 |
| logBtnHeight |
CGFloat |
登錄按鈕高 注意:必須大于40 |
| logBtnOffsetY |
NSNumber |
登錄按鈕Y偏移量 |
| logBtnOffsetY_B |
NSNumber |
登錄按鈕高距離底部的高度 |
| logBtnOriginLR |
NSArray |
登錄按鈕的左右邊距 示例:@[@50,@70] 只能兩個元素 |
| logBtnImgs |
NSArray |
登錄按鈕背景圖片添加到數(shù)組(順序如下)@[激活狀態(tài)的圖片,失效狀態(tài)的圖片,高亮狀態(tài)的圖片] |
5.4.隱私欄
| 方法 |
參數(shù)類型 |
說明 |
| uncheckedImg |
UIImage |
復選框未選中時圖片 |
| checkedImg |
UIImage |
復選框選中時圖片 |
| checkboxWH |
NSNumber |
復選框大?。ㄖ荒苷叫危┍仨毚笥?2 |
| appPrivacyOriginLR |
NSArray |
隱私條款(包括check框)的左右邊距 |
| appPrivacyDemo |
NSAttributedString |
隱私的內(nèi)容模板:1、全句可自定義但必須保留"&&默認&&"字段表明SDK默認協(xié)議,否則設置不生效 2、協(xié)議1和協(xié)議2的名稱要與數(shù)組 str1 和 str2 ... 里的名稱 一樣3、必設置項(參考SDK的demo) appPrivacieDemo設置內(nèi)容:登錄并同意&&默認&&和&&百度協(xié)議&&、&&京東協(xié)議2&&登錄并支持一鍵登錄 展示: 登錄并同意中國移動條款協(xié)議和百度協(xié)議1、京東協(xié)議2登錄并支持一鍵登錄 |
| appPrivacy |
NSArray |
隱私條款:數(shù)組(務必按順序)要設置NSLinkAttributeName屬性可以跳轉(zhuǎn)協(xié)議 |
| privacySymbol |
BOOL |
隱私條款默認協(xié)議是否開啟書名號 |
| privacyState |
BOOL |
隱私條款check框默認狀態(tài) 默認:NO |
| privacyColor |
string |
設置隱私欄復選框選中時圖片 |
| setPrivacyOffsetY |
NSNumber |
設置隱私欄相對于標題欄下邊緣的y偏移 |
| setPrivacyOffsetY_B |
NSNumber |
設置隱私欄相對于屏幕底部的y偏移 |
5.5.自定義布局
| 方法 |
參數(shù)類型 |
說明 |
| authPageBackgroundImage |
UIImage |
授權(quán)界面背景圖片 |
5.6.轉(zhuǎn)場動畫
| 方法 |
參數(shù)類型 |
說明 |
| presentType |
UAPresentationDirection |
授權(quán)界面推出時的方向,此屬性當authWindow為NO時設置才有效 UAPresentationDirectionBottom = 0, //底部 present默認效果 UAPresentationDirectionRight, //右邊 導航欄效果 UAPresentationDirectionTop, //上面 UAPresentationDirectionLeft //左邊 |
5.7.彈窗模式
| 方法 |
參數(shù)類型 |
說明 |
| authWindow |
BOOL |
彈窗模式開關(guān) |
| modalTransitionStyle |
UIModalTransitionStyle |
彈窗模式推出動畫 只咋在彈窗模式下生效UIModalTransitionStyleCoverVertical, 下推 UIModalTransitionStyleFlipHorizontal,翻轉(zhuǎn) UIModalTransitionStyleCrossDissolve, 淡出 |
6.退出授權(quán)頁界面
在authViewBlock返回的customView里添加Button并綁定點擊事件
- (void)addSubviewsIntoCustomView:(UIView *)customView withNumberFrame:(CGRect)numberFrame loginBtnFrame:(CGRect)loginBtnFrame checkBoxFrame:(CGRect)checkBoxFrame privacyFrame:(CGRect)privacyFrame
{
CGFloat top = Height_StatusBar;
CGFloat height = Height_NavBar;
if (_authViewModel.authWindow) {
top = 0;
height = 44;
}
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
backButton.frame = CGRectMake(10, top, 40, 40);
backButton.tintColor = [UIColor whiteColor];
[backButton setImage:[UIImage imageNamed:@"titlebar_icon_back"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, customView.frame.size.width, height)];
navView.backgroundColor = ThemeColor;
[customView addSubview:navView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, top, customView.frame.size.width, 44)];
titleLabel.font = [UIFont systemFontOfSize:17];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"一鍵登錄";
[navView addSubview:titleLabel];
[navView addSubview:backButton];
}
- (void)backButtonAction {
NSNumber *type = [[MWUniLoginSDK shareInstance] getOperatorType];
//移動卡直接退出
if ([type intValue] == 1) {
[self dismissViewControllerAnimated:YES completion:nil];
} else {
//聯(lián)通、電信卡則發(fā)送以下通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"authViewDisMissKey" object:nil];
}
}
SDK一鍵登錄完成回調(diào)后,不會立即關(guān)閉授權(quán)頁面,需要開發(fā)者主動調(diào)用此方法去完成頁面的關(guān)閉。授權(quán)頁的退出完全由APP控制,注意需要在主線程調(diào)用此函數(shù)。
7.獲取當前SIM卡的運營商
接口說明
- (NSNumber*_Nonnull)getOperatorType;
返回值
| 參數(shù) |
類型 |
說明 |
| 函數(shù)返回值 |
NSNumber |
NSNumber |
運營商類型 @return 運營商類型 1移動,2聯(lián)通,3電信 |
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。