tech talk salesforce mobile sdk

25
Salesforce Mobile SDK ISV Architect, 中嶋 一樹

Upload: kazuki-nakajima

Post on 28-Nov-2014

4.750 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tech talk   salesforce mobile sdk

Salesforce Mobile SDKISV Architect, 中嶋 一樹

Page 2: Tech talk   salesforce mobile sdk

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 such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements 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 of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology 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 and delivering 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 our security measures, the outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, 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, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended April 30, 2011. This documents and others containing important disclosures 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 not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

Page 3: Tech talk   salesforce mobile sdk
Page 4: Tech talk   salesforce mobile sdk

ネイティブアプリ

Page 5: Tech talk   salesforce mobile sdk

iOSネイティブアプリの特徴

•リッチなユーザーインターフェース•デバイス機能の活用•App Storeでの配信•XcodeとObjective Cで開発•ホーム画面に残る

Page 6: Tech talk   salesforce mobile sdk

リソースサーバ

データベース

API

Force.comと連携するiOSネイティブアプリのアーキテクチャ

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

Page 7: Tech talk   salesforce mobile sdk

Demo App

Page 8: Tech talk   salesforce mobile sdk

Mobile SDKのインストールとプロジェクト作成

$ git clone https://github.com/forcedotcom/SalesforceMobileSDK-iOS.gt

githubのレポジトリをクローン(ダウンロード)

$ cd SalesforceMobileSDK-iOS/$ ./install.sh

インストールスクリプトを実行

Xcodeのインストール

Native Force.com REST Appテンプレートからプロジェクトを作成

*Use Automatic Reference Countingのチェックをはずす

Page 9: Tech talk   salesforce mobile sdk

Mobile SDK Nativeテンプレートの構造

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

AppDelegate

認証後のアプリケーションのメイン画面を制御*サンプルアプリではユーザ名を10個取得し、テーブルビューに表示

Consumer IDとCallback URLを設定

認証画面を制御

UIApplicationDelegateプロトコルに従い、アプリケーション起動から認証までの挙動を担当

Page 10: Tech talk   salesforce mobile sdk

SFNativeRestAppDelegate

didFinishLauchingWithOptions:(NSDictionary *)launchOptions

setupAuthorizingViewController

rootViewControllerにSFAuthorizingViewControllerのインスタンスをセットし、アクティブに

setupAuthorizingViewControllerをキック

loggedIn

newRootViewControllerをキックしrootViewControllerにRootViewController(アプリのコントローラ)をセットし、アクティブに*newRootViewControllerはAppDelegateで実装されている

Page 11: Tech talk   salesforce mobile sdk

RootViewController

viewDidLoad

didLoadResponse:(id)jsonResponse

レスポンスをself.datarowsにセット

メニューバーのタイトルをセットForce.comからユーザー名を10個取得

cellForRowAtIndexPath:(NSIndexPath *)indexPath

テーブルのセルをデキューまたは生成し、ユーザー名をセット

SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:@"SELECT Name FROM User LIMIT 10"]; [[SFRestAPI sharedInstance] send:request delegate:self];

Page 12: Tech talk   salesforce mobile sdk

SFAuthCoodinatorDelegate

AppDelegate

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

SFRestAPI

UITableViewControllerUIViewControllerUIApplicationDelegate

SFRestRequest

UIAlertViewDelegate

Subclass

Subclass

Protocol

Subclass

Import

Import

Page 13: Tech talk   salesforce mobile sdk

NSString *objectType = @"Contact"; NSDictionary *fields = [@"{FirstName:Kazuki, LastName:Nakajima}" JSONValue];

SFRestRequest *request = [[SFRestAPI sharedInstance] requestForCreateWithObjectType:objectType fields:fields];

[[SFRestAPI sharedInstance] send:request delegate:self];

CRUD操作

NSString *objectId = @"1234567890";NSString *objectType = @"Contact"; SFRestRequest *request = [[SFRestAPI sharedInstance]

requestForDeleteWithObjectType:objectType objectId:objectId];

[[SFRestAPI sharedInstance] send:request delegate:self];

レコード作成

レコード削除

Page 14: Tech talk   salesforce mobile sdk

ハイブリッドアプリ

Page 15: Tech talk   salesforce mobile sdk

iOSハイブリッドアプリの特徴

•Web技術での開発•デバイス機能を呼び出し可能•App Storeでの配信•ホーム画面に残る

Page 16: Tech talk   salesforce mobile sdk

リソースサーバ

データベース

API

Force.comと連携するiOSハイブリッドアプリのアーキテクチャ

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

Force.com Javascript REST Toolkit

Page 17: Tech talk   salesforce mobile sdk

Demo App

Page 18: Tech talk   salesforce mobile sdk

プロジェクト作成

Hybrid Force.com Appテンプレートからプロジェクトを作成*Use Automatic Reference Countingのチェックをはずす

wwwフォルダを右クリックして一旦削除するポップアップではRemove Referencesをクリック

プロジェクトを右クリックしてshow in finderを選択し、wwwフォルダをドラッグ&ドロップでプロジェクトに追加する*Copy items into destination group’s folder (if needed)を選択*Create folder references for any added foldersを選択

wwwフォルダが青色であることを確認する

Page 19: Tech talk   salesforce mobile sdk

Mobile SDK Hybridテンプレートの構造

inline.js

index.html

forcetk.js

bootconfig.js

Force.com JavaScript REST Toolkit。RESTアクセスのラッパー

Consumer IDとCallback URL等の設定を記述

アプリケーションのメイン画面

サンプルアプリの処理

SalesforceOAuthPlugin.js

PhoneGapのAPIを利用して認証処理を実装

phonegap-x.x.x.jsPhoneGapのAPIを提供

Page 20: Tech talk   salesforce mobile sdk

bootconfig.jsdebugMode = true | false;

remoteAccessConsumerKey = xxx;

コンシューマ鍵をセット

logToConsoleメソッドの出力がスクリーンに表示されるかどうか

oauthRedirectURI = [xxx]

コールバックURLをセット

oauthScopes = ['xxx','xxx'];

発行されるトークンの権限

startData = new SFHybridApp.LocalAppStartData(); | new SFHybridApp.RemoteAppStartData("[VFページのパス]");

コンテンツがローカル管理の場合はLocalAppStartData()をセットコンテンツがVisualforce管理の場合はRemoteAppStartData()をセット

autoRefreshOnForeground = true | false;

OAuthセッションを自動リフレッシュするかどうか

Page 21: Tech talk   salesforce mobile sdk

index.html

jQuery(document).ready(function(){}

onDeviceReady(){}

SalesforceOAuthPlugin.getAuthCredentials()をキックsalesforceSessionRefreshイベント発生時にsalesforceSessionRefreshed()をキックすることを登録reLinkClickHandlers()をキック(サンプルアプリのクリックイベントを登録)

devicereadyイベント発生時にonDeviceReady()をキックすることを登録

salesforceSessionRefreshed(){}

forcetk.Clientのインスタンスを生成し、認証で得られたトークンをセット

Page 22: Tech talk   salesforce mobile sdk

PhongeGap.plist*ファイルの場所はプロジェクト名 > Supporting Files > PhoneGap.plist

ExternalHosts

JavaScriptやCSSのライブラリを外部サーバから読み込む場合はドメインを明記する必要がある

Page 23: Tech talk   salesforce mobile sdk

Force.com JavaScript REST Toolkit

レコード作成

SOQL発行

forcetkClient.query(soql, callback, error);

forcetkClient.create(objtype, fields, callback, error);

Apex Rest発行

forcetk.Client.apexrest(path, callback, error, method, payload, retry);

レコード削除forcetkClient.del(objtype, id, callback, error);

インスタンス生成var forcetkClient = new forcetk.Client(clientId, loginUrl, proxyUrl);

forcetkClient.setSessionToken(sessionId, apiVersion, instanceUrl);トークンセット

Page 24: Tech talk   salesforce mobile sdk

PhoneGapで提供される機能

各APIについて詳しくはhttp://docs.phonegap.com/en/1.6.1/index.htmlを参照

加速度センサーカメラコンパス連絡先ストレージ

位置情報プッシュ通知音楽データマイク回線

$j(document).on('tap', '#page_create_survey #button_capture_business_card', function(){ navigator.camera.getPicture(onCameraSuccess, onCameraFail, { quality: 50, destinationType: Camera.DestinationType.DATA_URL }); });

カメラ呼び出しの例

Page 25: Tech talk   salesforce mobile sdk

ありがとうございました!