Slide 1

Slide 1 text

CodePushとReact Nativeで 緊急OTAリリース!了解! Masayuki Iwai@myb #iosdc

Slide 2

Slide 2 text

CodePushとReact Nativeで 緊急OTAリリース!了解! Masayuki Iwai@myb #iosdc ホットパッチング

Slide 3

Slide 3 text

自己紹介 岩井雅幸@myb
 
 モバイル・アプリケーション・エンジニア
 at Unity Technologies Japan
 以前はWebデザイン・開発、Flashコンテ ンツ制作、iOSアプリ、ゲーム制作など 著書に「uGUIではじめる Unity UIデザイン の教科書」

Slide 4

Slide 4 text

自己紹介 岩井雅幸@myb
 
 モバイル・アプリケーション・エンジニア
 at Unity Technologies Japan
 以前はWebデザイン・開発、Flashコンテ ンツ制作、iOSアプリ、ゲーム制作など 著書に「uGUIではじめる Unity UIデザイン の教科書」

Slide 5

Slide 5 text

こんなアプリを作っています

Slide 6

Slide 6 text

Unity Meetup • Unityユーザーのためのイベントアプリ
 イベント検索、タイムテーブル、参加申し
 込み、チェックイン、アンケート回答機能 • フルReact Native
 導入の経緯は昨年のiOSDC 2017 Reject Conf での発表を参照
 https://www.slideshare.net/MasayukiIwai/ react-native-110226150

Slide 7

Slide 7 text

トラブルが…

Slide 8

Slide 8 text

2018年5月

Slide 9

Slide 9 text

Unite Tokyo 2018での出来事

Slide 10

Slide 10 text

Unite Tokyo 2018での出来事 • 毎年開催しているUnity公式のカンファレンス • 今年は5月に3日間開催、2000人以上参加 • このイベントに合わせてチャット機能を実装 • 海外チームが開発しているAPIを利用する必要があり、
 連携を依頼していたがギリギリになってしまった • 前バージョンでパフォーマンスが悪かったのでリファクタリング

Slide 11

Slide 11 text

Unite Tokyo 2018での出来事 • イベント3日前に新バージョン完成、申請→翌朝審査通過 • イベント前日の夜、新機能の表示系バグを発見、修正→翌未明審査通過 • イベント初日の夜、重大なバグを発見 →特急審査を依頼して4時間で審査通過

Slide 12

Slide 12 text

正直しんどかった

Slide 13

Slide 13 text

CodePushを導入していれば ホットパッチングできたのに…

Slide 14

Slide 14 text

なんで導入して いなかったのか…

Slide 15

Slide 15 text

なんで導入していなかったのか… • なんか面倒そうだったので後回しにしていた • Appleの審査が十分早かったのであまり必要性を感じていなかった

Slide 16

Slide 16 text

後悔先に立たず

Slide 17

Slide 17 text

時すでにお

Slide 18

Slide 18 text

What is CodePush?

Slide 19

Slide 19 text

の前に

Slide 20

Slide 20 text

ざっくりReact Native

Slide 21

Slide 21 text

ざっくりReact Native • Reactベースでネイティブアプリ開発のためのフレームワーク • React由来のコンポーネントベースで、reduxとも親和性が高い • JavaScript(JSX)で記述、JavaScriptCore上で動作 https://facebook.github.io/react-native/

Slide 22

Slide 22 text

ざっくりReact Native UIKitなど React Native Library JavaScriptCore React JS アプリケーションコード React Native JS Library

Slide 23

Slide 23 text

ざっくりReact Native UIKitなど React Native Library JavaScriptCore React JS アプリケーションコード React Native JS Library jsbundle

Slide 24

Slide 24 text

What is CodePush?

Slide 25

Slide 25 text

What is CodePush? • Microsoft製のクラウドサービス • React NativeやCordovaのJSコードをホットパッチング可能 • ウェブ、SDK、CLIが提供されている • 以前は独立したサービス
 →現在はVisual Studio App Centerに統合 https://github.com/Microsoft/code-push

Slide 26

Slide 26 text

What is CodePush? UIKitなど React Native Library JavaScriptCore React JS アプリケーションコード React Native JS Library jsbundle ここの部分 を配信

Slide 27

Slide 27 text

Visual Studio App Center • CodePushの他にも
 CI、テスト、Analytics、 Push通知など多機能 • 無料から利用可能
 (ビルド回数や時間に制限有) • CodePushは無料で無制限に 利用可能 https://appcenter.ms

Slide 28

Slide 28 text

Visual Studio App Center • CodePushの他にも
 CI、テスト、Analytics、 Push通知など多機能 • 無料から利用可能
 (ビルド回数や時間に制限有) • CodePushは無料で無制限に 利用可能 https://appcenter.ms

Slide 29

Slide 29 text

Fantastic

Slide 30

Slide 30 text

でも…

Slide 31

Slide 31 text

ホットパッチングって 大丈夫なの?

Slide 32

Slide 32 text

終わりなきリジェクト との戦い

Slide 33

Slide 33 text

Appleのガイドラインを
 振り返る

Slide 34

Slide 34 text

Appleのガイドラインを振り返る 2.7 Apps that download code in any way or form will be rejected 2.8 Apps that install or launch other executable code will be rejected App Store Review Guidelines (2015)

Slide 35

Slide 35 text

Appleのガイドラインを振り返る 2.7 Apps that download code in any way or form will be rejected 2.8 Apps that install or launch other executable code will be rejected App Store Review Guidelines (2015)

Slide 36

Slide 36 text

Appleのガイドラインを振り返る 2.5.2 Apps should be self-contained in their bundles, and may not read or write data outside the designated container area, nor may they download, install, or execute code which introduces or changes features or functionality of the app, including other apps. (抜粋) App Store Review Guidelines (2016)

Slide 37

Slide 37 text

Appleのガイドラインを振り返る 2.5.2 Apps should be self-contained in their bundles, and may not read or write data outside the designated container area, nor may they download, install, or execute code which introduces or changes features or functionality of the app, including other apps. (抜粋) App Store Review Guidelines (2016)

Slide 38

Slide 38 text

Appleのガイドラインを振り返る 3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple's built-in WebKit framework or JavascriptCore, provided that such scripts and code do not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store. Apple Developer Program License Agreement (2016)

Slide 39

Slide 39 text

Appleのガイドラインを振り返る 3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple's built-in WebKit framework or JavascriptCore, provided that such scripts and code do not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store. Apple Developer Program License Agreement (2016)

Slide 40

Slide 40 text

Appleのガイドラインを振り返る 3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple's built-in WebKit framework or JavascriptCore, provided that such scripts and code do not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store. Apple Developer Program License Agreement (2016)

Slide 41

Slide 41 text

Appleのガイドラインを振り返る 3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple's built-in WebKit framework or JavascriptCore, provided that such scripts and code do not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store. Apple Developer Program License Agreement (2016)

Slide 42

Slide 42 text

Appleのガイドラインを振り返る • アプリは、機能を変えるようなコードをダウンロード、インストール、
 実行してはならない • インタープリテッドコードは、すべてのスクリプトがアプリに含まれて
 いる必要がある • 唯一の例外は、WebKitやJavaScriptCoreによってダウンロード、実行
 される場合のみ

Slide 43

Slide 43 text

React Nativeは JavaScriptCore上で 動くので-

Slide 44

Slide 44 text

現在のAppleのガイドライン 3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS. Apple Developer Program License Agreement (Current)

Slide 45

Slide 45 text

現在のAppleのガイドライン 3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS. Apple Developer Program License Agreement (Current)

Slide 46

Slide 46 text

現在のAppleのガイドライン 3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS. Apple Developer Program License Agreement (Current)

Slide 47

Slide 47 text

現在のAppleのガイドライン 3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS. Apple Developer Program License Agreement (Current)

Slide 48

Slide 48 text

現在のAppleのガイドライン 3.3.2 Except as set forth in the next paragraph, an Application may not download or install executable code. Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS. Apple Developer Program License Agreement (Current)

Slide 49

Slide 49 text

現在のAppleのガイドライン • App Storeに申請されたのと違う機能を提供して、アプリの主目的を
 変えない • 他のコードやアプリのストアやストアフロントを作成しない • 署名やサンドボックスその他OSのセキュリティ機能を迂回しない →以上の条件を満たして入れば、実行可能なコードをダウンロードする
 ことはOK

Slide 50

Slide 50 text

CodePushによる ホットパッチングは合法 用法・用量を守って正しくお使いください

Slide 51

Slide 51 text

同様のサービスは?

Slide 52

Slide 52 text

同様のサービスは? • Rollout.io、JSPatch →2017年3月、これらを使用していた開発者にAppleから警告
 Apple Developer Program License Agreementと
 App Store Review Guidelinesに抵触 →リジェクト対象に https://forums.developer.apple.com/thread/73640

Slide 53

Slide 53 text

同様のサービスは? “This includes any code which passes arbitrary parameters to dynamic methods such as dlopen(), dlsym(), respondsToSelector:, performSelector:, method_exchangeImplementations(), and running remote scripts in order to change app behavior or call SPI, based on the contents of the downloaded script. Even if the remote resource is not intentionally malicious, it could easily be hijacked via a Man In The Middle (MiTM) attack, which can pose a serious security vulnerability to users of your app.” https://forums.developer.apple.com/thread/73640

Slide 54

Slide 54 text

同様のサービスは? “This includes any code which passes arbitrary parameters to dynamic methods such as dlopen(), dlsym(), respondsToSelector:, performSelector:, method_exchangeImplementations(), and running remote scripts in order to change app behavior or call SPI, based on the contents of the downloaded script. Even if the remote resource is not intentionally malicious, it could easily be hijacked via a Man In The Middle (MiTM) attack, which can pose a serious security vulnerability to users of your app.” https://forums.developer.apple.com/thread/73640

Slide 55

Slide 55 text

同様のサービスは? “This includes any code which passes arbitrary parameters to dynamic methods such as dlopen(), dlsym(), respondsToSelector:, performSelector:, method_exchangeImplementations(), and running remote scripts in order to change app behavior or call SPI, based on the contents of the downloaded script. Even if the remote resource is not intentionally malicious, it could easily be hijacked via a Man In The Middle (MiTM) attack, which can pose a serious security vulnerability to users of your app.” https://forums.developer.apple.com/thread/73640

Slide 56

Slide 56 text

セキュリティの 観点からダメ

Slide 57

Slide 57 text

ホットパッチング自体は合法

Slide 58

Slide 58 text

CodePushを使ってみよう

Slide 59

Slide 59 text

CodePushを使ってみよう 1. App Centerでアプリを登録する 2. App Center CLIをインストール 3. React Native Client SDKをインストール 4. アプリケーションコードの修正

Slide 60

Slide 60 text

1. App Centerで
 アプリを登録する

Slide 61

Slide 61 text

1. App Centerでアプリを登録する

Slide 62

Slide 62 text

1. App Centerでアプリを登録する

Slide 63

Slide 63 text

1. App Centerでアプリを登録する

Slide 64

Slide 64 text

1. App Centerでアプリを登録する

Slide 65

Slide 65 text

1. App Centerでアプリを登録する

Slide 66

Slide 66 text

1. App Centerでアプリを登録する

Slide 67

Slide 67 text

1. App Centerでアプリを登録する

Slide 68

Slide 68 text

1. App Centerでアプリを登録する

Slide 69

Slide 69 text

1. App Centerでアプリを登録する

Slide 70

Slide 70 text

1. App Centerでアプリを登録する

Slide 71

Slide 71 text

2. App Center CLIを
 インストール

Slide 72

Slide 72 text

2. App Center CLIをインストール $ brew install node $ npm install -g appcenter-cli

Slide 73

Slide 73 text

2. App Center CLIをインストール $ appcenter login 
 Opening your browser...
 ? Visit https://appcenter.ms/cli-login?hostname=xxx.local and enter the code:
 ? Access code from browser: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Logged in as xxxxxxxx

Slide 74

Slide 74 text

2. App Center CLIをインストール $ appcenter codepush deployment list -a / 
 !""""""""""""#"""""""""""""""""""""""""""""""""""""""$
 % Name % Key %
 &""""""""""""'"""""""""""""""""""""""""""""""""""""""(
 % Staging % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %
 &""""""""""""'"""""""""""""""""""""""""""""""""""""""(
 % Production % xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %
 )""""""""""""*"""""""""""""""""""""""""""""""""""""""+

Slide 75

Slide 75 text

3. React Native Client SDKを インストール

Slide 76

Slide 76 text

3. React Native Client SDKをインストール $ cd /path/to/project $ npm install --save react-native-code-push

Slide 77

Slide 77 text

3. React Native Client SDKをインストール $ react-native link react-native-code-push ... ? What is your CodePush deployment key for Android (hit to ignore) ... ? What is your CodePush deployment key for iOS (hit to ignore)

Slide 78

Slide 78 text

4. アプリケーションコードの修正

Slide 79

Slide 79 text

4. アプリケーションコードの修正 App.js export default class App extends React.Component { // ... }

Slide 80

Slide 80 text

4. アプリケーションコードの修正 App.js import codePush from ‘react-native-code-push’ class App extends React.Component { // ... } App = codePush(App) export default App

Slide 81

Slide 81 text

4. アプリケーションコードの修正 App.js import codePush from ‘react-native-code-push’ class App extends React.Component { // ... } App = codePush({ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME, installMode: codePush.InstallMode.ON_NEXT_RESUME, )(App) export default App

Slide 82

Slide 82 text

That’s it!

Slide 83

Slide 83 text

CodePushで配信してみよう

Slide 84

Slide 84 text

CodePushで配信してみよう $ appcenter codepush release-react -a / -d Staging

Slide 85

Slide 85 text

Demo https://github.com/miyabi/iosdc18example

Slide 86

Slide 86 text

まとめ • CodePushの導入は簡単!デプロイも簡単! • Appleのガイドライン的にもOKなので安心して使える!
 (ガイドラインに従って適切に使いましょう) • JavaScript部分のみの配信なので、適用できるところは限られる
 (既存アプリへの導入も可能)

Slide 87

Slide 87 text

Thank you!