data apiで作る スマホアプリ
TRANSCRIPT
Data API で作るスマホアプリ2016/02/22エムロジック株式会社 関根元和
@MT 東京 -21 Data API 3.0
自己紹介
関根元和エムロジック株式会社 取締役iOS アプリの開発をしていますStoryEditor 、ペタろう、 PiloWeb 、 MovableType 日本語版、 CuteDbook 、 Twit 、 BPM 、ミイル、 SUGARWAVE 、トレタ、 SENSEINOTE
Movable Type for iOS
CHEEBOW
週末音楽家作曲、編曲、プロデュースライブアイドルを中心に楽曲提供しています
夢眠ねむ ( でんぱ組 .inc)ディアステージアイドル部愛乙女★ DOLLCOSMIC STAGEDoll☆Elements
Jewel Kiss逢沢ありあT!P丸山夏鈴asfi佐野友里子 ( 愛乙女★ DOLL)
Honey Squashハックガールズ白鹿はるの飴涙めるLuce Twinkle Wink☆
マボロシ可憐 GeNE留守番ガールズハピドル〜 Happy Idol Project 〜佐原百音Ange☆Reve
PIP: Platonics Idol PlatformPICK UP GIRLS 」Carnival☆StarsRYUKYU IDOLじぇるの!
S☆UTHERN CROSSLovin & S
SnowRabbit feat. 鈴木ゆきLasRabbi神宿
CAMOUFLAGE
割とガチ
Movable Type とわたし
iOS アプリ開発
必要なものMacXcodeApple Developer ProgramiPhone
Mac
Mac
iMacMacBook ProMacBook AirMac ならどれでも大丈夫です!OS X Yosemite 10.10.5 以上
Xcode
Xcode
アプリを作るために必要なものが全部入っていますしかも無料! Mac App Store からダウンロードできます最新バージョンは Xcode 7 。 iOS 9 に対応させるには Xcode 7 が必要です!
Apple Developer Program
Apple Developer Program
App Store でアプリを配布するために必要年間参加費 11,800 円たとえ配布するのが無料アプリでも、年間参加費が必要です新しい OS もいち早く試すことができます
iPhone
iPhone
開発そのものは実機がなくてもできますしかし、リリース前には「ほんとに動くのか」確認した方が良いでしょう普段使っている iPhone でも大丈夫ですiPad にも対応させるなら iPad での確認も必要です
開発言語
Objective-CSwift
Objective-C
C 言語 + オブジェクト指向
float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; if (ver >= 7.0) { [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; }
Objective-C
第一印象なんか大カッコ( [] )多すぎ気持ち悪い…
Swift
2014 年生まれの新しい言語オープンソースObjective-C よりスッキリしたコードが書けます
let ver = (UIDevice.currentDevice().systemVersion as NSString).floatValueif ver >= 7.0 { UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent}
Swift
すっきり!今選ぶなら Swift でしょうただし、 Objective-C の知識も必要になることがあります
DataAPI を使う
DataAPI を使って Movable Type にアクセスしますiOS アプリ開発では、 Swift で書かれたSDK を使います
Swift 用 SDK
https://github.com/movabletype/mt-data-api-sdk-swift
CocoaPods
https://cocoapods.org/Mac アプリや iOS アプリ開発者向けのライブラリ管理ツールCocoaPods を使えば簡単に DataAPI SDKを組み込めます
platform :ios, '8.0'use_frameworks!
pod 'MTDataAPI-SDK'
pod install
CocoaPods の使い方詳しくは公式ページを参照https://guides.cocoapods.org/
ブログ一覧の取得
import MTDataAPI_SDK
let api = DataAPI.sharedInstanceapi.APIBaseURL = “http://host/mt/mt-data-api.cgi"
api.authentication("username", password: "password", remember: true, success:{_ in api.listSites( success: {(result: [JSON]!, total: Int!)-> Void in print(items) }, failure: {(error: JSON!)-> Void in } ) }, failure: {(error: JSON!)-> Void in })
記事の作成
import MTDataAPI_SDK
let api = DataAPI.sharedInstanceapi.APIBaseURL = "http://host/mt/mt-data-api.cgi"
var entry = [String:String]()entry["title"] = "title"entry["body"] = "text"entry["status"] = "Publish"
api.authentication("username", password: "password", remember: true, success:{_ in api.createEntry(siteID: "1", entry: entry, success: {(result: JSON!)-> Void in print(result) }, failure: {(error: JSON!)-> Void in } ) }, failure: {(error: JSON!)-> Void in })
画像のアップロード
import MTDataAPI_SDK
let api = DataAPI.sharedInstanceapi.APIBaseURL = “http://host/mt/mt-data-api.cgi"
api.authentication("username", password: "password", remember: true, success: {_ in let image = UIImage(named:"photo") let data = UIImageJPEGRepresentation(image!, 1.0) api.uploadAssetForSite("1", assetData: data!, fileName: "photo.jpeg", options: ["path":"/images", "autoRenameIfExists":"true"], success: {(result: JSON!)-> Void in print(result) }, failure: {(error: JSON!)-> Void in } ) }, failure: {(error: JSON!)-> Void in })
DataAPI で広がる世界
DataAPI を使ったチャットアプリ
仕組み
Movable Type の記事 = チャットルーム記事へのコメント = 発言
デモ
JSQMessagesViewController
オープンソースのチャット UI ライブラリhttps://github.com/jessesquires/JSQMessagesViewController
メッセージ送信
var comment = [String:String]()comment["body"] = text
self.inputToolbar?.contentView?.rightBarButtonItem?.enabled = false
self.api.authentication(USERNAME, password: PASSWORD, remember: true, success:{_ in self.api.createCommentForEntry( siteID: self.SITE_ID, entryID: self.ENTRY_ID, comment: comment, success: {(result: JSON!)-> Void in self.inputToolbar?.contentView?.rightBarButtonItem?.enabled = true self.finishSendingMessageAnimated(true) self.receiveMessage() }, failure: {(error: JSON!)-> Void in self.inputToolbar?.contentView?.rightBarButtonItem?.enabled = true } ) }, failure: {(error: JSON!)-> Void in self.inputToolbar?.contentView?.rightBarButtonItem?.enabled = true })
メッセージ受信
let options = [ "limit":"100", "no_text_filter":"1", "fields":"author,body"]
self.api.authentication(USERNAME, password: PASSWORD, remember: true, success:{_ in self.api.listCommentsForEntry( siteID: self.SITE_ID, entryID: self.ENTRY_ID, options: options, success: {(items:[JSON]!, total:Int!)-> Void in self.messagesFromJSON(items) }, failure: {(error: JSON!)-> Void in } ) }, failure: {(error: JSON!)-> Void in })
再構築どうせデータにアクセスするだけなのでテンプレートは空でもいいのでは再構築のない世界へ (笑 )API に「再構築しない」オプションが追加されるといいなぁ……
MT≠CMS
Blog ツールとして生まれた MTCMS と進化しそして、 Web アプリのバックエンドへ
興味のある方は
https://github.com/cheebow/MTChatAppプロジェクトがダウンロードできます
まとめ
DataAPI + iOS
Movable Type をカスタマイズ自由なWeb アプリケーションのバックエンドとしてDataAPI で簡単にアクセス夢が広がりますね!
iOS アプリ開発
iOS アプリの開発は敷居が高いかも……そんな時は、ぜひ、エムロジック株式会社にお問い合わせください!
質疑応答
おしまい