15
15

More than 5 years have passed since last update.

【iOS開発】Digitsで無料のSMS認証を試しんぐ

Last updated at Posted at 2014-11-14

Digits

Digitsは無料でSMS認証ができるフレームワークで、Twitter社が公開したFabricというフレームワーク郡の一部です。今回はこれを試しんぐ。

FabricのSDKは現在(2014/11/14)、限られた人数にしか公開されておらず、使うためには順番待ちする必要があります・・・ (筆者は1週間位待ちましたが、順番が来なかったので問い合わせのメールを何通か送ったら順番が回ってきました。)

下準備

Fabricにログインし、Fabricクライアントアプリケーションをインストールしましょう。クライアントを使ってXcodeプロジェクトに簡単に各フレームワークを組み込めるので大変便利です。

組み込みのボタンクラスを使う

#import <TwitterKit/TwitterKit.h>
.
.
.
    DGTAuthenticateButton *authenticateButton = [DGTAuthenticateButton buttonWithAuthenticationCompletion:^(DGTSession *session, NSError *error) {
        // 認証のコールバック。errorに何か入ってたり、sessionがnilだったらエラーハンドリングしましょう。
    }];
    authenticateButton.center = self.view.center;
    [self.view addSubview:authenticateButton];

最短で、この組み込みのボタンを設置するだけでSMS認証を実装できます。。。すばらしい。DGTSessionクラスから電話番号やユーザーID、トークンなどが取得できます。

コードから認証機能を呼び出す

#import <TwitterKit/TwitterKit.h>
.
.
.
//一番シンプルなパターン。ただ認証のUIを呼び出すだけ
    [[Digits sharedInstance] authenticateWithCompletion:^(DGTSession *session, NSError *error){
        //認証のコールバック
    }];
//認証のUIを呼び出しつつ、そのタイトルだけ変えたいとき
    [[Digits sharedInstance] authenticateWithTitle:<任意のタイトル> completion:^(DGTSession *session, NSError *error){
            //認証のコールバック
    }];
//認証のモーダルビューを表示するViewControllerを指定したいとき
    [[Digits sharedInstance] authenticateWithViewController:<任意のコントローラ> title:<任意のタイトル> completion:^(DGTSession *session, NSError *error){
        //認証のコールバック
    }];

※シミュレーターでは言語設定を日本語にしても、組み込みのUIが英語表示されるのですが、実機ではちゃんと日本語で表示されました。

参考
https://dev.twitter.com/twitter-kit/ios-reference





ブログもみてね☆

15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15