Your SlideShare is downloading. ×
勉強会force#2 HTML5によるモバイルアプリ開発
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

勉強会force#2 HTML5によるモバイルアプリ開発


Published on

Published in: Technology, Design
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. 勉強会force#2HTML5によるモバイルアプリ開発 ISV Architect 中嶋一樹
  • 2. Safe HarborSafe harbor statement under the Private Securities Litigation Reform Act of 1995:This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any suchuncertainties materialize or if any of the assumptions proves incorrect, the results of, inc. could differmaterially from the results expressed or implied by the forward-looking statements we make. All statements other thanstatements of historical fact could be deemed forward-looking, including any projections of product or service availability,subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans ofmanagement for future operations, statements of belief, any statements concerning new, planned, or upgraded services ortechnology developments and customer contracts or use of our services.The risks and uncertainties referred to above include – but are not limited to – risks associated with developing anddelivering new functionality for our service, new products and services, our new business model, our past operating losses,possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of oursecurity measures, the outcome of intellectual property and other litigation, risks associated with possible mergers andacquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain,and motivate our employees and manage our growth, new releases of our service and successful customer deployment, ourlimited history reselling products, and utilization and selling to larger enterprise customers. Furtherinformation on potential factors that could affect the financial results of, inc. is included in our annual reporton Form 10-Q for the most recent fiscal quarter ended April 30, 2011. This documents and others containing importantdisclosures are available on the SEC Filings section of the Investor Information section of our Web site.Any unreleased services or features referenced in this or other presentations, press releases or public statements are notcurrently available and may not be delivered on time or at all. Customers who purchase our services should make thepurchase decisions based upon features that are currently available., inc. assumes no obligation and doesnot intend to update these forward-looking statements.
  • 3. アーキテクチャ
  • 4. 3タイプのアプリケーションNative• オンラインストアからインストール• モバイル端末のH/W機能を活用• リッチなユーザエクスペリエンス• 特殊な開発能力が必要
  • 5. 3タイプのアプリケーションWeb• ブラウザからアクセス• 端末を問わないシングルコードベース• 限定的なH/Wアクセス• 非互換なイベント• 開発者を確保し易いWebベースの開発
  • 6. 3タイプのアプリケーションWeb + HTML5• ブラウザからアクセス• 端末を問わないシングルコードベース• 限定的なH/Wアクセス• Nativeのようなモバイル用UI• 開発者を確保し易いWebベースの開発
  • 7. 3タイプのアプリケーションHybrid• オンラインストアからインストール• モバイル端末のH/Wを活用• リッチなユーザエクスペリエンス• 開発者を確保し易いWebベースの開発
  • 8. Force.comでのWeb + HTML5アプリ提供形態 Database Apex Visualforce js / css 3rd Party HTML5
  • 9. Database.comでのWeb + HTML5アプリ提供形態 Database Apex API Open Web Platform js / css 3rd Party HTML5
  • 10. サンプルアプリ
  • 11. User: mobile@sugoisurvey21.devPassword: force0202
  • 12. User Interface
  • 13. Visualforce PageにjQuery Mobileをロード<apex:page sidebar="false" showHeader="false" standardStylesheets="false"standardController="Session__c" extensions="sugoiSurvey" contentType="text/html" doctype="HTML-5.0"><apex:stylesheet value="" /><apex:includescript value="" /><apex:includescript value="" /><head> <title>{!$label.sugoiSurvey}</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <script type="text/javascript"> j$ = jQuery.noConflict(); </script>• <apex:stylesheet>,<apex:includescript>でライブラリ(jQuery, jQuery Mobile)をロード• <meta name="viewport">で表示サイズをモバイル端末画面に最適化• jQuery.noConfilict();で$を変更
  • 14. jQuery Mobileでのページ構造<div id="session_list" data-role="page"> <div data-role="header"> </div> <div data-role="content"> <a href="#session_detail">Session 1</a> </div> <div data-role="footer"> </div></div><div id="session_detail" data-role="page" data-add-back-btn="true"> <div data-role="header"> </div> <div data-role="content"> </div> <div data-role="footer"> </div></div>• <div data-role="page">で1つの画面を表示• 1htmlファイルに複数の画面を記述可能。デフォルトでは最初のpageを表示。• ページ内リンク<a href="#{ID}">にて画面遷移。各<div>にid="{ID}"を設定しておく• data-add-back-btn="true"でヘッダにbackボタンを自動表示可能
  • 15. リスト<div id="session_list" data-role="page" > <div data-role="header"><h1>セッションリスト</h1></div> <div data-role="content"> <ul data-role="listview" data-inset="true" data-filter="true"> <li><a href="#session1">Session 1</a></li> <li><a href="#session2">Session 2</a></li> <li><a href="#session3">Session 3</a></li> </ul> </div></div><div id="session1" data-role="page" data-add-back-btn="true"> <div data-role="header"><h1>セッション詳細</h1></div> <div data-role="content"> <ul data-role="listview"> <li data-role="list-divider">Session 1</li> <li>セッション 1の詳細</li> </ul> </div></div>• <ul data-role=”listview”>でTouchに適したリストを表示• <ul data-filter=”true”>でリスト絞り込み用サーチボックスを表示• <li data-role=”list-divider”>でリストの見出を設定
  • 16. サンプルアプリのトップページ<div id="session_list" data-role="page" data-theme="d"> <div data-role="header"> <h1>{!$label.sessionList}</h1> <a href="#create_session" class="ui-btn-right" data-icon="plus" data-transition="slideup">{!$}</a> </div> <div data-role="content"> <ul data-role="listview" data-inset="true" data-divider-theme="d" data-filter="true" data-split-icon="gear"> <apex:repeat var="session" value="{!sessions}"> <li class="session"> <a href="/apex/sugoiSurveyM_detail?id={!}" data-ajax="false"> <h3>{!}</h3> <p> {!session.presenter__r.company__c} {!session.presenter__r.title__c} {!}<br /> {!YEAR(session.Date__c)}.{!MONTH(session.Date__c)}.{!DAY(session.Date__c)} #{!session.hash_tag__c} </p> <span class="ui-li-count">{!session.rate_avg__c}pt</span> </a> <a href="/apex/sugoiSurveyM_edit?id={!}" data-ajax="false"></a> </li> </apex:repeat> </ul> </div></div>
  • 17. データベース操作
  • 18. JavaScript RemotingでApexを実行Apex@RemoteActionpublic static void submitSurveyJs(id session, string rate){ survey__c survey = new survey__c(session__c = session, rate__c = rate); insert survey;}• @RemoteActionアノテーションを対応Methodに付加• global/publicかつstaticのMethodを定義Visulaforce Pagej$(#submit_survey).tap(function(){ var rate = j$(input:radio:checked).val(); sugoiSurvey.submitSurveyJs( "{!}", rate, function(result, event){ alert(event.message); }, {escape:true} );});• sugoiSurvey.submitSurveyJs() => {Class名}.{Method名}()で対応するApexを実行• resultでクラスからの返り値を参照• eventでApexからの実行結果を参照
  • 19.
  • 20. 認証
  • 21. OAuth (PHP + REST)OAuth Toolkit for PHPをドキュメントルートに設置認証下に置くphpファイルの先頭<?phpsession_start();if (!isset($_SESSION[access_token]) || !isset($_SESSION[instance_url])) { $_SESSION[oauth_return] = $_SERVER[PHP_SELF] . ? . htmlspecialchars(SID); header( Location: /oauth/oauth.php? . htmlspecialchars(SID));}• 認証されているセッションは常に$_SESSION[‘access_token’]にTokenを保持• Tokenがなければ、 1.ローカルのOAuthライブラリにリダイレクト。 2.Salesforceの認証サーバにリダイレクトされ、認証 => 「コード」取得。 3.ローカルのOAuthライブラリにリダイレクト。SalesforceのTokenサーバからTokenを取得。 4.$_SESSION[‘access_token’]にTokenを保存し認証下のコンテンツにリダイレクト。
  • 22. データベース操作
  • 23. OAuth (PHP + REST)Tokenを用いたREST APIアクセス$query = ‘select name from session__c’;$url = $_SESSION[‘instance_url’] . “/services/data/" . VERSION . "/query?q=" . urlencode($query);$curl = curl_init($url);curl_setopt($curl, CURLOPT_HEADER, false);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: OAuth “ . $_SESSION[‘access_token’]));$json_response = curl_exec($curl);$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);if ($status != 200) { if ($status == 401){ $response = json_decode($json_response); if ($response[0]->errorCode == INVALID_SESSION_ID) { header( Location: oauth/oauth.php ); } } $curl_error = curl_error($curl); $curl_errno = curl_errno($curl); die("Status Code: $status <br/>Response: $json_response <br/> Curl Error: $curl_error <br/>Curl Errno:$curl_errno");}curl_close($curl);$response = json_decode($json_response, true);return($response);
  • 24. OAuth (PHP + JavaScript + REST) JavaScript REST API Toolkit forcetk.js
  • 25. OAuth (PHP + JavaScript + REST) JavaScript REST API Toolkitをドキュメントルートに設置[root@server]# ls ${DOCUMENT_ROOT}/forcetk.jsproxy.phpindex.phpoauth/HTMLから読み込み<!DOCTYPE html><html><head> <title><?php echo LABEL_SUGOISURVEY; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="" rel="stylesheet" type="text/css" /> <script type="text/javascript" src=""></script> <script type="text/javascript" src=""></script> <script type="text/javascript" src="forcetk.js"></script></head>
  • 26. OAuth (PHP + JavaScript + REST)POSTでレコードを作成<script type=”text/javascript”> $(document).ready(function(){ var $client_id = "[あなたのConsumer ID]"; var $proxy_url = "https://[あなたのWebサーバ]/proxy.php?mode=native"; // REST APIアクセスを抽象化するWrapperを初期化 var client = new forcetk.Client($client_id, null, $proxy_url); // セッション情報をセット client.setSessionToken(<?php echo $_SESSION["access_token"]; ?>, null, <?php echo$_SESSION["instance_url"]; ?>); $(#account_form :button).click(function(){ var $account_name = $(#account_form :text).attr(value); // createメソッドでAccountレコードを作成。第一引数はオブジェクト名。第二引数はフィールド。第三引数は成功時のコールバック。第四引数はエラー時のコールバック。 client.create( "Account", {"Name":$account_name}, function(response){ alert(Success!); }, function(jqXHR){ alert(jqXHR.responseText); } ); }); });</script>