勉強会force#3 iosアプリ開発

28
iOSアプリ開発 ISV Architect 中嶋 一樹 勉強会force #3

Upload: kazuki-nakajima

Post on 18-Nov-2014

1.457 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 勉強会force#3 iOSアプリ開発

iOSアプリ開発ISV Architect 中嶋 一樹

勉強会force #3

Page 2: 勉強会force#3 iOSアプリ開発

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: 勉強会force#3 iOSアプリ開発

AppExchange Conference 2012.02606人が来場

Page 4: 勉強会force#3 iOSアプリ開発

すごいアンケート• HTML5で構築• Heroku + Force.comで稼働 

• 379 のアンケート• 199 のコメント

Page 5: 勉強会force#3 iOSアプリ開発

ネイティブアプリ

Page 6: 勉強会force#3 iOSアプリ開発

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

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

Page 7: 勉強会force#3 iOSアプリ開発

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

Page 8: 勉強会force#3 iOSアプリ開発

リソースサーバ

データベース

API

Force.com

Apex

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

メール配信 Chatterで情報連携 レポートで分析

Page 9: 勉強会force#3 iOSアプリ開発

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 10: 勉強会force#3 iOSアプリ開発

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

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

AppDelegate

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

Consumer IDとCallback URLを設定

認証画面を制御

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

Page 11: 勉強会force#3 iOSアプリ開発

SFNativeRestAppDelegate

didFinishLauchingWithOptions:(NSDictionary *)launchOptions

setupAuthorizingViewController

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

setupAuthorizingViewControllerをキック

loggedIn

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

Page 12: 勉強会force#3 iOSアプリ開発

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 13: 勉強会force#3 iOSアプリ開発

SFAuthCoodinatorDelegate

AppDelegate

SFNativeRestAppDelegate

SFAuthorizingViewController

RootViewController

SFRestAPI

UITableViewControllerUIViewControllerUIApplicationDelegate

SFRestRequest

UIAlertViewDelegate

Subclass

Subclass

Protocol

Subclass

Import

Import

Page 14: 勉強会force#3 iOSアプリ開発

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 15: 勉強会force#3 iOSアプリ開発

ハイブリッドアプリ

Page 16: 勉強会force#3 iOSアプリ開発

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

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

Page 17: 勉強会force#3 iOSアプリ開発

リソースサーバ

データベース

API

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

Force.com

Apex

iOS SDK

Salesforce Mobile SDK

認証サーバ

①認証・認可

②アクセストークン

③リクエスト

Force.com Javascript REST Toolkit

Page 18: 勉強会force#3 iOSアプリ開発

プロジェクト作成

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: 勉強会force#3 iOSアプリ開発

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: 勉強会force#3 iOSアプリ開発

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: 勉強会force#3 iOSアプリ開発

index.html

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

onDeviceReady(){}

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

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

salesforceSessionRefreshed(){}

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

Page 22: 勉強会force#3 iOSアプリ開発

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

ExternalHosts

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

Page 23: 勉強会force#3 iOSアプリ開発

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: 勉強会force#3 iOSアプリ開発

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: 勉強会force#3 iOSアプリ開発

アプリ配布

Page 26: 勉強会force#3 iOSアプリ開発
Page 27: 勉強会force#3 iOSアプリ開発

タイプ毎の配布

パターン①:Directory / ISVforce Application (旧AppExchange)

パターン②:OEM Application

パターン③:Database.com

•組織はすでにある前提なので単にアプリを配布すればOK。•リスティングはApp StoreとAppExchangeに。• HTML5アプリであればログイン後にUserAgentによってリダイレクトするなど。•ネイティブ、ハイブリッドはHOMEにインストール情報を掲載しておくなど。

•最初はまず組織プロビジョンニングする必要あり。•リスティングはApp StoreとAppExchangeに。• HTML5アプリであればログイン後にUserAgentによってリダイレクトするなど。•ネイティブ、ハイブリッドはHOMEにインストール情報を掲載しておくなど。

•ユーザー数、データ量、トランザクション量で課金。•パートナープログラムは今のところありません。(2012年4月現在)•複数組織で構成することもできるし、単一組織で構成することもできる。(ガバナ制限に注意)

Page 28: 勉強会force#3 iOSアプリ開発

その他

• OAuth 2.0をマスターしよう。http://wiki.developerforce.com/page/JP:Digging_Deeper_into_OAuth_2.0_at_Salesforce.com

• username/passwordフローではLogin IPレンジに注意。

• Aloha認定を取得しよう。

• Sitesはトライアル環境毎に有効化申請が必要です。

• ベンダー側でおこなうサイト毎のカスタマイズはなくそう。

• HTML5、ハイブリッドでは 基本はVisualforceで完結しつつ、

パッチでの修正をおこなう

• Web側の機能追加が頻発する場合はherokuを利用するなど。