More Related Content
Similar to HTML+COIMOTION 開發跨平台 app (20)
HTML+COIMOTION 開發跨平台 app
- 3. ⼯工具 / 材料清單
ü npm + PhoneGap
ü Ant: 建⽴立 Android 版本時需要
ü Cordova camera plugin
ü COIMOTION PhoneGap SDK
ü (optional) Genymotion 如果要在
Mac 上跑,還需要 Virtuebox
- 5. API清單
代碼
說明
API 路徑
UserProfile
檢測使⽤用者是不是在登⼊入
狀態
core/user/profile
Login
使⽤用者登⼊入
core/user/login
Register
使⽤用者註冊
core/user/register
NotesList
列出筆記清單
[myRepo]/notes/list
NoteView
取得筆記的完整內容
[myRepo]/notes/view
NoteCreate
新增⼀一條筆記
[myRepo]/notes/create
A@achPic
將照⽚片附加在筆記上
[myRepo]/notes/a@ach
* myRepo: ⽤用⾃自訂內容集所對應的代碼取代
- 17. 安裝Cordova / 建⽴立 App
#
安裝 cordova
>
sudo
npm
install
–g
cordova
#
建⽴立
App
>
cordova
create
wnote
com.gocharm.coim.wnote
WireNotes
#
建⽴立所⽀支援的平台環境
>
cd
wnote
>
cordova
plaLorm
add
ios
>
cordova
plaLorm
add
android
# build
>
cordova
build
- 18. #
安裝模擬器 Genymotion
#
啟動程式
>
cordova
run
android
測試看看
#
安裝模擬啟動程式
>
sudo
npm
install
ios-‐sim
-‐g
#
啟動模擬器
>
cordova
emulate
ios
OK!!
iOS:
Android:
- 19. 下載範例程式
1. git
clone
h@ps://github.com/coimoFon/
coApp.git
.
2. 或者到 github.com/coimoFon/coApp
去下載 zip
檔
3. 將下載內容中 www ⺫⽬目錄整個複製到 wnote ⺫⽬目
錄下(覆蓋掉 PhoneGap 的 demo)
4. 把 config.xml 也取代掉
- 20. 安裝PhoneGap Plugin
#
安裝照相功能的
plugin
>
cordova
plugin
add
org.apache.cordova.camera
#安裝 COIMOTION
SDK
plugin
>
cordova
plugin
add
h@ps://github.com/coimoFon/coimPlugin.git
- 21. ⼦子端與 API 的對話
經由 SDK 的幫忙,App 和後端程式溝通可以很容易
達成。但需要先告訴 SDK ⼆二件事:
o appCode: ⾏行動應⽤用程式的代碼
o appKey:⾏行動應⽤用程式的⾦金鑰
- 24. ⼦子端的設定 -- iOS
在 wnote/plaLorms/ios/wnote/wnote-‐Info.plist 中加⼊入
⼆二個 property:
• coim_app_key
• coim_app_code
其內容值就是我們剛才找的 appKey
和 appCode
- 25. ⼦子端的設定 -- Android
在 wnote/plaLorms/android/AndroidManifest.xml 中,
<applicaFon>
tag 內加⼊入⼆二個 <meta-‐data>
tag:
<meta-‐data
android:name=“coim_app_key”
android:value=“”
/>
<meta-‐data
android:name=“coim_app_code”
android:value=“”
/>
其內容值就是我們剛才找的 appKey
和 appCode
- 26. 修改 index.html
我們利⽤用 index.html 將App 所需的⾴頁⾯面⾃自動產⽣生,並
告知所對應的 API 服務:
25 <script
type=“text/javascript”>
26
var
pages
=
[
27
{id:
‘home’},
28
{id:
‘login’},
29
{id:
‘list’,
remote:
‘WireNotes/notes/list’},
30
{id:
‘view’,
remote:
‘WIreNotes/notes/view’},
31
{id:
‘edit’}
32
];
33
34
_wf.iniFalize(pages);
35 </script>
改成你的⾃自製內容集的代碼
- 28. 可以跑程式了
#
安裝模擬器 Genymotion
#
啟動程式
>
cordova
run
android
#
安裝模擬啟動程式
>
sudo
npm
install
ios-‐sim
-‐g
#
啟動模擬器
>
cordova
emulate
ios
iOS:
Android:
- 32. 拍照
var
options
=
{
sourceType:
Camera.PictureSourceType.CAMERA,
targetWidth:
640,
targetHeight:
640
};
navigator.camera.getPicture(function(imgPath){
…
},
null,
options);
www/blocks/edit/edit.js: 13 ~ 19
- 34. 顯⽰示資料清單
var
pages
=
[
{id:
'home'},
{id:
'login'},
{id:
'list',
remote:
'WireNotes/notes/list',
params:
{pri:1}},
{id:
'view',
remote:
'WireNotes/notes/view',
params:
{pic:1}},
{id:
'edit',
remote:
'WireNotes/notes/view’}
];
_wf.iniFalize(pages);
Index.html: 26 ~ 34
程式起始時,在 index.html 曾做過以下的事:
list ⾴頁⾯面要顯⽰示時,coapp.js 會從 WireNotes/
notes/list 讀取資料
- 35. 顯⽰示單筆資料
<div
id="noteBody">
{{#each
value.picList}}
<div
style="text-‐align:center;">
<img
src=""
data-‐path="{{dataURI}}"
/>
</div>
{{/each}}
</div>
<hr
/>
<p>{{body}}</p>
www/blocks/view/view.html: 12 ~ 20
資料讀取原理和 list (清單)類似,以下顯⽰示
畫⾯面處理:
- 40. 參考資訊
coServ: 以 node.js 實作的新⼀一代 Web Server
http://github.com/coimotion/coServ
coServ 中⽂文版技術⽂文件
http://coimotion.github.io/coServ/zh/index.html
使⽤用 COIMOTION的 Android 範例
https://github.com/coimotion/Android-Demo-App
使⽤用 COIMOTION的 iOS範例
https://github.com/coimotion/iOS-Demo-App