iOS のエンドツーエンドのデモンストレーション
improve this page | report issue概説
このデモンストレーションの目的は、エンドツーエンドのフローを体験することです。
- MobileFirst クライアント SDK と事前にバンドルされているサンプル・アプリケーションは登録済みで、MobileFirst Operations Console からダウンロードされています。
- 新規または提供済みのアダプターは MobileFirst Operations Console にデプロイされています。
- アプリケーション・ロジックは、リソース要求を行うために変更されています。
終了結果:
- MobileFirst Server を正常に ping している。
- アダプターを使用してデータを正常に取得している。
前提条件:
1. MobileFirst Server の開始
Mobile Foundation インスタンスが作成済みであることを確認してください。作成済みでない場合は、
MobileFirst Developer Kitを使用しているときは、サーバーのフォルダーにナビゲートして、Mac および Linux では ./run.sh
、Windows では run.cmd
のコマンドを実行してください。
2. アプリケーションの作成
ブラウザー・ウィンドウで、URL http://your-server-host:server-port/mfpconsole
をロードして MobileFirst Operations Console を開きます。 ローカルで実行している場合は、http://localhost:9080/mfpconsole を使用します。 ユーザー名/パスワードは admin/admin です。
- アプリケーションの隣の「新規」ボタンをクリックします。
- iOS プラットフォームを選択します。
- (次のステップでダウンロードするアプリケーション・スキャフォールドに応じて) com.ibm.mfpstarteriosobjectivec または com.ibm.mfpstarteriosswift を アプリケーション ID として入力します。
- 1.0 を version の値として入力します。
- 「アプリケーションの登録」をクリックします。
-
「スターター・コードの取得」タイルをクリックして、iOS Objective-C または iOS Swift サンプル・アプリケーションをダウンロードすることを選択します。
3. アプリケーション・ロジックの編集
-
.xcworkspace ファイルをダブルクリックして Xcode プロジェクトを開きます。
-
[project-root]/ViewController.m/swift ファイルを選択し、以下のコード・スニペットを貼り付けて、既存の
getAccessToken()
関数を置換します。Objective-C の場合:
- (IBAction)getAccessToken:(id)sender { _testServerButton.enabled = NO; NSURL *serverURL = [[WLClient sharedInstance] serverUrl]; _connectionStatusLabel.text = [NSString stringWithFormat:@"Connecting to server...\n%@", serverURL]; NSLog(@"Testing Server Connection"); [[WLAuthorizationManager sharedInstance] obtainAccessTokenForScope:@"" withCompletionHandler:^(AccessToken *token, NSError *error) { if (error != nil) { _titleLabel.text = @"Bummer..."; _connectionStatusLabel.text = [NSString stringWithFormat:@"Failed to connect to MobileFirst Server\n%@", serverURL]; NSLog(@"Did not receive an access token from server: %@", error.description); } else { _titleLabel.text = @"Yay!"; _connectionStatusLabel.text = [NSString stringWithFormat:@"Connected to MobileFirst Server\n%@", serverURL]; NSLog(@"Received the following access token value: %@", token.value); NSURL* url = [NSURL URLWithString:@"/adapters/javaAdapter/resource/greet/"]; WLResourceRequest* request = [WLResourceRequest requestWithURL:url method:WLHttpMethodGet]; [request setQueryParameterValue:@"world" forName:@"name"]; [request sendWithCompletionHandler:^(WLResponse *response, NSError *error) { if (error != nil){ NSLog(@"Failure: %@",error.description); } else if (response != nil){ // Will print "Hello world" in the Xcode Console. NSLog(@"Success: %@",response.responseText); } }]; } _testServerButton.enabled = YES; }]; }
Swift の場合:
@IBAction func getAccessToken(sender: AnyObject) { self.testServerButton.isEnabled = false let serverURL = WLClientSwift.sharedInstance().serverUrl(); connectionStatusLabel.text = "Connecting to server...\n\(String(describing: serverURL))" print("Testing Server Connection") WLAuthorizationManagerSwift.sharedInstance().obtainAccessToken(forScope: nil) { (token,error) -> Void in if (error != nil) { self.titleLabel.text = "Bummer..." self.connectionStatusLabel.text = "Failed to connect to MobileFirst Server\n\(String(describing: serverURL))" print("Did not receive an access token from server: " + error.debugDescription) } else { self.titleLabel.text = "Yay!" self.connectionStatusLabel.text = "Connected to MobileFirst Server\n\(String(describing: serverURL))" print("Received the following access token value: " + (token?.value)!); let url = URL(string: "/adapters/javaAdapter/resource/greet/"); let request = WLResourceRequestSwift(url: url!, method: WLResourceRequestSwift.WLHttpMethodGet); request.setQueryParameterValue(parameterValue: "world", forName: "name"); request.send(onCompletion: { (response, error) in if (error != nil){ print("Failure: " , error!); } else if (response != nil){ print("Success: " + response!.responseText); } }) } self.testServerButton.isEnabled = true } }
4. アダプターのデプロイ
この作成済みの .adapter 成果物をダウンロードし、MobileFirst Operations Console から「アクション」→「アダプターのデプロイ」アクションを使用して、この成果物をデプロイします。
あるいは、「アダプター」の隣の「新規」ボタンをクリックします。
-
「アクション」→「サンプルのダウンロード」オプションを選択します。 「Hello World」Java アダプターのサンプルをダウンロードします。
Maven および MobileFirst CLI がインストールされていない場合は、スクリーン内の「開発環境をセットアップします」の説明に従います。
-
コマンド・ライン・ウィンドウからアダプターの Maven プロジェクト・ルート・フォルダーにナビゲートし、以下のコマンドを実行します。
mfpdev adapter build
-
ビルドが終了したら、「アクション」→「アダプターのデプロイ」アクションを使用して MobileFirst Operations Console からアダプターをデプロイします。 アダプターは、[adapter]/target フォルダー内にあります。
5. アプリケーションのテスト
- Xcode で、mfpclient.plist ファイルを選択し、protocol、host、port の各プロパティーをご使用の MobileFirst Server の正しい値で編集します。
- ローカル MobileFirst Server を使用している場合、通常、値は http、localhost、および 9080 です。
- リモート MobileFirst Server (IBM Cloud 上) を使用している場合、通常、値は https、your-server-address、および 443 です。
- IBM Cloud Private 上で Kubernetes クラスターを使用していて、デプロイメントのタイプが NodePort の場合、通常、ポートの値は、Kubernetes クラスターのサービスによって公開される NodePort です。
あるいは、MobileFirst CLI がインストール済みの場合は、プロジェクト・ルート・フォルダーにナビゲートし、コマンド
mfpdev app register
を実行します。 リモート MobileFirst Server が使用されている場合は、コマンドmfpdev server add
を実行してサーバーを追加し、続いて、例えば、mfpdev app register myIBMCloudServer
を実行します。 - 「再生」ボタンを押します。
結果
- 「MobileFirst Server への ping (Ping MobileFirst Server)」ボタンをクリックすると、「MobileFirst Server に接続されています (Connected to MobileFirst Server)」が表示されます。
- アプリケーションが MobileFirst Server に接続できた場合は、デプロイした Java アダプターを使用してリソース要求呼び出しが行われます。
その場合、アダプター応答が Xcode コンソールに出力されます。
次の手順
アプリケーションでのアダプターの使用、プッシュ通知などの追加のサービスを統合する方法、MobileFirst セキュリティー・フレームワークの使用などについて学習します。
- アプリケーションの開発チュートリアルを検討する
- アダプターの開発チュートリアルを検討する
- 認証およびセキュリティー・チュートリアルを検討する
- 通知チュートリアルを検討する
- すべてのチュートリアルを検討する
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.