salesforce mobile sdk webinar

29
Salesforce Mobile SDK ISV Architect, 中嶋 一樹 1

Upload: salesforce-developers-japan

Post on 28-Nov-2014

1.922 views

Category:

Technology


7 download

DESCRIPTION

「Salesforce mobile SDK Webinar」の発表資料です。 Developer Force JapanではForce.com開発者に必要な各種技術資料の公開や、Webinarセミナー等を定期的に開催しております。 http://jp.force.com/

TRANSCRIPT

Page 1: Salesforce mobile SDK Webinar

Salesforce Mobile SDKISV Architect, 中嶋 一樹

1

Page 2: Salesforce mobile SDK Webinar

Safe Harbor

Safe 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.

2

Page 3: Salesforce mobile SDK Webinar

3

Page 4: Salesforce mobile SDK Webinar

3

Page 5: Salesforce mobile SDK Webinar

ネイティブアプリ

4

Page 6: Salesforce mobile SDK Webinar

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

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

5

Page 7: Salesforce mobile SDK Webinar

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

6

Page 8: Salesforce mobile SDK Webinar

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

6

Page 9: Salesforce mobile SDK Webinar

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

6

Page 10: Salesforce mobile SDK Webinar

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

6

Page 11: Salesforce mobile SDK Webinar

Demo App

7

Page 12: Salesforce mobile SDK Webinar

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のチェックをはずす

8

Page 13: Salesforce mobile SDK Webinar

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

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

AppDelegate

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

Consumer IDとCallback URLを設定

認証画面を制御

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

9

Page 14: Salesforce mobile SDK Webinar

SFNativeRestAppDelegate

didFinishLauchingWithOptions:(NSDictionary *)launchOptions

setupAuthorizingViewController

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

setupAuthorizingViewControllerをキック

loggedIn

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

10

Page 15: Salesforce mobile SDK Webinar

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];

11

Page 16: Salesforce mobile SDK Webinar

SFAuthCoodinatorDelegate

AppDelegate

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

SFRestAPI

UITableViewControllerUIViewControllerUIApplicationDelegate

SFRestRequest

UIAlertViewDelegate

Subclass

Subclass

Protocol

Subclass

Import

Import

12

Page 17: Salesforce mobile SDK Webinar

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];

レコード作成

レコード削除

13

Page 18: Salesforce mobile SDK Webinar

ハイブリッドアプリ

14

Page 19: Salesforce mobile SDK Webinar

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

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

15

Page 20: Salesforce mobile SDK Webinar

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

Force.com Javascript REST Toolkit

16

Page 21: Salesforce mobile SDK Webinar

Demo App

17

Page 22: Salesforce mobile SDK Webinar

プロジェクト作成

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フォルダが青色であることを確認する

18

Page 23: Salesforce mobile SDK Webinar

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.js

PhoneGapのAPIを提供

19

Page 24: Salesforce mobile SDK Webinar

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セッションを自動リフレッシュするかどうか

20

Page 25: Salesforce mobile SDK Webinar

index.html

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

onDeviceReady(){}

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

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

salesforceSessionRefreshed(){}

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

21

Page 26: Salesforce mobile SDK Webinar

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

ExternalHosts

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

22

Page 27: Salesforce mobile SDK Webinar

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);トークンセット

23

Page 28: Salesforce mobile SDK Webinar

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 }); });

カメラ呼び出しの例

24

Page 29: Salesforce mobile SDK Webinar

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

25