iOS使用技能 - 簡訊,語言驗證碼的擷取與驗證小結

來源:互聯網
上載者:User

標籤:

最近有學習一個小技能,這裡小結一下,分享給大家,互相交流。

首先是大體步驟:

  1. 在mob官網註冊,然後添加簡訊驗證的應用
  2. 使用cocoapods匯入架構
Podfile檔案:platform :ios, "6.0"target ‘簡訊驗證‘do# Mob產品公用庫
pod ‘MOBFoundation_IDFA‘
# SMSSDK必須pod ‘SMSSDK‘end 

3.在AppDelegate註冊應用AppKey

4.擷取驗證碼

5.提交驗證碼

6.注意點:適配要記得開啟https

1.在AppDelegate

 

//  註冊AppKey [SMSSDK registerApp:@"14810905c09b0" withSecret:@"fbea3e77174d8c9da1d0839b1f0bdc82"];

 

如:

 

2.簡訊和語言各一個簡單方法即可實現

/** *  簡訊驗證碼 */- (IBAction)messageVerify {    //  驗證電話號碼是否合法    NSString *phoneNumber = self.phoneNumber.text;    if (![phoneNumber isPhone]) {        NSLog(@"你輸入電話號碼不正確");        return;    }    self.savePhoneNumber = phoneNumber;    //  擷取簡訊驗證碼    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:phoneNumber zone:@"86" customIdentifier:nil result:^(NSError *error) {        if (error) {            NSLog(@"擷取驗證碼失敗:%@",error);        }else{            NSLog(@"擷取驗證碼成功");        }    }];}/** *  語言驗證碼 */- (IBAction)voiceVerify {    //  驗證電話號碼是否合法    NSString *phoneNumber = self.phoneNumber.text;    if (![phoneNumber isPhone]) {        NSLog(@"你輸入電話號碼不正確");        return;    }    self.savePhoneNumber = phoneNumber;    //  擷取語音驗證碼    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodVoice phoneNumber:phoneNumber zone:@"86" customIdentifier:nil result:^(NSError *error) {        if (error) {            NSLog(@"擷取驗證碼失敗:%@",error);        }else{            NSLog(@"擷取驗證碼成功");        }    }];}/** *  驗證 */- (IBAction)verifyResult {    //  驗證驗證碼是否合法    NSString *verifyCode   = self.verifyLabel.text;    if (verifyCode.length != 4) {        NSLog(@"驗證輸入錯誤");        return;    }    //  提交驗證碼    [SMSSDK commitVerificationCode:verifyCode phoneNumber:self.savePhoneNumber zone:@"86" result:^(NSError *error) {        if (!error) {            NSLog(@"驗證成功");        }else{            NSLog(@"錯誤資訊:%@",error);        }    }];}

上例是使用mob預設的簡訊格式,也可以自訂,可根據自身情況來選擇。

其他還有一些修改,大家可以閱讀mob上的sdk文檔來整合自己需要的形式。

 

 

iOS使用技能 - 簡訊,語言驗證碼的擷取與驗證小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.