Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
iOSアプリでMTを256倍使う
Search
CHEEBOW
January 14, 2017
Programming
0
150
iOSアプリでMTを256倍使う
「【MT東京−31】バレンタインデー1ヶ月前から始める Swift×MT Data API」で行われたセッションの資料です
CHEEBOW
January 14, 2017
Tweet
Share
More Decks by CHEEBOW
See All by CHEEBOW
プログラマのための音楽入門
cheebow
5
760
Other Decks in Programming
See All in Programming
AI時代のドメイン駆動設計-DDD実践におけるAI活用のあり方 / ddd-in-ai-era
minodriven
23
9k
私の後悔をAWS DMSで解決した話
hiramax
4
140
コーディングエージェント時代のNeovim
key60228
1
110
ワープロって実は計算機で
pepepper
2
1.4k
コンテキストエンジニアリング Cursor編
kinopeee
1
710
未来を拓くAI技術〜エージェント開発とAI駆動開発〜
leveragestech
2
180
兎に角、コードレビュー
mitohato14
0
150
Langfuseと歩む生成AI活用推進
licux
3
300
オープンセミナー2025@広島「君はどこで動かすか?」アンケート結果
satoshi256kbyte
0
210
管你要 trace 什麼、bpftrace 用下去就對了 — COSCUP 2025
shunghsiyu
0
470
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.1k
「リーダーは意思決定する人」って本当?~ 学びを現場で活かす、リーダー4ヶ月目の試行錯誤 ~
marina1017
0
240
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
55
13k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Making Projects Easy
brettharned
117
6.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Become a Pro
speakerdeck
PRO
29
5.5k
Navigating Team Friction
lara
189
15k
Into the Great Unknown - MozCon
thekraken
40
2k
Site-Speed That Sticks
csswizardry
10
790
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Transcript
iOSΞϓϦͰ MTΛ256ഒ͏ 2017/01/14 ΤϜϩδοΫגࣜձࣾɹؔࠜݩ @MT౦ژ−31 Swift×MT Data API
ࣗݾհ
ؔࠜݩ ΤϜϩδοΫגࣜձࣾɹऔక iOSΞϓϦͷ։ൃΛ͍ͯ͠·͢ StoryEditorɺϖλΖ͏ɺPiloWebɺMovableTypeຊ ޠ൛ɺCuteDbookɺTwitɺBPMɺϛΠϧɺτϨ λɺSENSEINOTEɺϨγϐϒϩά
τϨλ
Ϩγϐϒϩά
Movable Type for iOS
Movable Type Data API SDK for Swift
Movable TypeͱΘͨ͠
͜Μͳຊॻ͖·ͨ͠
CHEEBOW िԻָՈ ࡞ۂɺฤۂɺϓϩσϡʔε ϥΠϒΞΠυϧΛத৺ʹָۂఏڙ͍ͯ͠· ͢
ָۂఏڙͨ͠ΞΠυϧ ເͶΉ ͰΜͺJOD σΟΞεςʔδΞΠυϧ෦ѪԵঁ˒%0--$04.*$45"(& %PMMˑ&MFNFOUT+FXFM,JTT⁊͋Γ̩͋ʂؙ̥ࢁՆླBTpࠤ༑ཬࢠ Ѫ Եঁ˒%0-- )POFZ4RVBTIϋοΫΨʔϧζനࣛΔͷ᷒ྦΊΔ-VDF 5XJOLMF8JOLˑϚϘϩγՄ࿁(F/&ཹक൪Ψʔϧζϋϐυϧʙ)BQQZ*EPM1SPKFDU ʙࠤݪඦԻ"OHFˑ3FWF1*11MBUPOJDT*EPM1MBUGPSN1*$,61(*3-4ʯ
$BSOJWBMˑ4UBST3:6,:6*%0-͐͡Δͷʂ4ˑ65)&3/$3044-PWJOˍ4 4OPX3BCCJUGFBUླΏ͖-BT3BCCJਆ॓$".06'-"(&͓ΏͼϓϦϯηε ᗅΊ͖ˑΞϯϑΥϨϯτMJUUMFNPSFϕʔεϘʔϧΨʔϧζӬւఱΕʂݪ ॓BU.&$IVˑ0I%PMMZ,".0͕ωΪΛ͠ΐͬͯ͘Δο͔ΖΜͪΌΜ 3:6,:6*%0- ܭ
ΠϯλϏϡʔ https://japan.steinberg.net/jp/artists/steinberg_stories/cheebow.html
࿈ࡌ http://icon.jp/archives/13667
ͳʹ͕ຊۀ͔Θ͔Βͳ͍ ࠷ۙͰ ʮϓϩάϥϚΊͨΜͰ͔͢ʁʯ ͱฉ͔ΕΔ࢝ ͬͯ·͢ʂɹ SwiftͰίʔυॻ͍ͯ·͢ʂʂ
iOSΞϓϦ։ൃ
ඞཁͳͷ Mac Xcode Apple Developer Program iPhone
Mac
Mac iMac MacBook Pro MacBook Air MacͳΒͲΕͰେৎͰ͢ʂ ࠷৽OSͷํ͕ྑ͍Ͱ͢
Xcode
Xcode ΞϓϦΛ࡞ΔͨΊʹඞཁͳͷ͕શ෦ೖͬ ͍ͯ·͢ ͔͠ແྉʂ Mac App Store͔ΒμϯϩʔυͰ͖·͢ ࠷৽όʔδϣϯXcode 8.2
Apple Developer Program
Apple Developer Program App StoreͰΞϓϦΛ͢ΔͨΊʹඞཁ ؒࢀՃඅ 11,800ԁ ͨͱ͑͢Δͷ͕ແྉΞϓϦͰɺؒ ࢀՃඅ͕ඞཁͰ͢ ৽͍͠OS͍ͪૣ͘ࢼ͢͜ͱ͕Ͱ͖·͢
iPhone
iPhone ։ൃͦͷͷ࣮ػ͕ͳͯ͘Ͱ͖·͢ ͔͠͠ɺϦϦʔεલʹʮ΄Μͱʹಈ͘ͷ͔ʯ ֬ೝͨ͠ํ͕ྑ͍Ͱ͠ΐ͏ ීஈ͍ͬͯΔiPhoneͰେৎͰ͢ iPadʹରԠͤ͞ΔͳΒiPadͰͷ֬ೝඞཁͰ ͢
։ൃݴޠ Objective-C Swift
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).floatValue if ver >= 7.0
{ UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent }
Swift ͖ͬ͢Γʂ ࠓબͿͳΒSwiftͰܾ·Γʂ
Objective-CͬͯΦϫίϯͰ͠ΐ ఆ൪ϥΠϒϥϦͳͲObj-CͰॻ͔Εͨͷ ଟ͍ ॻ͘͜ͱͳͯ͘ಡΉ͜ͱඞཁʹͳΔ ͜ͱ
Data APIͱͳʹ͔
Data API Data API ʹ͍ͭͯ(https://www.sixapart.jp/movabletype/data-api/) “Data API ɺ͞·͟·ͳϓϩάϥϜݴޠ͔Β REST/JSONํࣜͰ Movable
Type ʹΞΫηε͠ɺσʔλͷऔಘߋ৽͕Ͱ͖ΔAPIͰɺMovable Type 6 ͔Β ࡌ͞Ε͍ͯ·͢ɻ Data API Λ͑ɺCMSͰཧ͍ͯ͠ΔσʔλΛɺαΠτ্Ͱࣗ༝ʹݺ ͼग़ͨ͠Γɺ·ͨɺಠࣗͷཧը໘ΞϓϦͷ։ൃɺଞͷϓϥοτ ϑΥʔϜͱͷ࿈ܞͳͲΛ༰қʹߦ͏͜ͱ͕Ͱ͖·͢ɻ”
Data API Data APIͰɺMovable TypeΛϒϩάπʔϧCMSΛ ͍͑ͨํΛ͢Δ͜ͱ͕Ͱ͖ΔΑ͏ʹͳΓ· ͢ WebαʔϏεͷόοΫΤϯυͱͯ͠ ೝূػೳඪ४Ͱ༻ҙ͞Ε͍ͯΔʂ API͢Ͱʹे༻ҙ͞Ε͍ͯΔʂ
Data APIͰͰ͖Δ͜ͱ
Ϣʔβೝূ ϩάΠϯػೳΛ࣋ͨͤΔ͜ͱ͕Ͱ͖·͢ ͪΖΜϩάΞτͰ͖·͢
औಘɺҰཡɺ࡞ɺߋ৽ɺআ ϒϩάͱΣϒαΠτ هࣄ ίϝϯτ ΧςΰϦ λά ΞΠςϜ
ݕࡧ هࣄͷݕࡧ͕Ͱ͖·͢
None
ཧը໘͔Βࣗ༝ʹͳΔʂ MTͰͰ͖Δ͜ͱ΄΅Ͱ͖·͢ʂ ͭ·Γ ཧը໘͔Βࣗ༝ʹͳΔʂ
MTͰ͋Δ͜ͱΛΕͯΈΔ MTͷཧը໘ = CMSͷཧը໘ MTΛ͏࣌ʹɺͲ͏ͯ͜͠ͷཧը໘ ʹࢧ͞Εͯ͠·͏ ൃ͑͞ ҰMTͰ͋Δ͜ͱΛΕͯΈ·͠ΐ͏
ࣗ༝ʹൃͯ͠ΈΔ ϒϩάͬͯϒϩάͱͯ͠Θͳ͍ͱ͍͚ͳ ͍ͷʁ هࣄͬͯهࣄͱͯ͠Θͳ͍ͱ͍͚ͳ͍ͷʁ ίϝϯτͬͯίϝϯτͱͯ͠Θͳ͍ͱ͍ ͚ͳ͍ͷʁ
ΣϒαΠτɺϒϩά ΣϒαΠτෳͷϒϩάΛ࣋ͭ͜ͱ͕ Ͱ͖Δ ෳͷهࣄΛ࣋ͭ͜ͱ͕Ͱ͖Δ ϒϩά͝ͱʹΧςΰϦλάΛܾΊΔ͜ͱ ͕Ͱ͖Δ
هࣄ ඪ४ͷϑΟʔϧυ͕͋Δ ΧελϜϑΟʔϧυͰ֦ுͰ͖Δ APIར༻Ͱ࠷͍Ͱͷ͋ΔΦϒδΣΫτ
ίϝϯτ Ұͭͷهࣄʹෳ͚ͭΔ͜ͱ͕Ͱ͖Δ ෳͷฦ৴ίϝϯτΛ࣋ͭ͜ͱ͕Ͱ͖Δ هࣄʹͿΒԼ͕Δใ
ΧςΰϦ ෳͷهࣄΛͿΒԼ͛Δ͜ͱ͕Ͱ͖Δ هࣄΛೖΕ͓ͯ͘ೖΕͷͱߟ͑ΒΕΔ ࣮ࡍɺΣϒϖʔδͰϑΥϧμͱͯ͠ ΘΕ·͢
λά هࣄΞΠςϜʹෳ͚ͭΔ͜ͱ͕Ͱ͖Δ هࣄΞΠςϜΛߜΓࠐΉͷʹ͑Δ
ΞΠςϜ ը૾ɺԻɺಈըͳͲςΩετҎ֎ͷσʔ λΛѻ͑Δ
֊ߏ ΣϒαΠτ ϒϩά ΧςΰϦ هࣄ ίϝϯτ
໊લʹΘ͞Εͳ͍ هࣄɺίϝϯτɺΧςΰϦɺλάͱ͍͏໊લͰ͍ํ ΛܾΊ͚ͭͯ͠·͏ ϒϩάΛϒϩάͱͯ͠Θͳ͍͜ͱͰɺCMSͱͯ͠ͷ ΘΕ͔ͨΛͨ͠Α͏ʹɺࣗ༝ʹൃͯ͠Έ·͠ΐ͏ ֓ཁΩʔϫʔυΛผͷ͍ํ͢Δͱ͔͋Δ͋ΔͰ͢ ΑͶ RenameLabelͬͯϓϥάΠϯΛ࡞Γ·ͨ͠
Data APIͷ͍ํ
Movable Type Data API SDK for Swift https://github.com/movabletype/mt-data-api-sdk-swift SwiftͰॻ͔Ε͍ͯ·͢ Swift3ରԠʂ
࣮ɺ͜ͷΠϕϯτͷొஃ͕ܾ·ͬͯɺ߄ͯͯࡢʹରԠ͠·ͨ͠ʂ
CocoaPods https://cocoapods.org/ Mac ΞϓϦ iOS ΞϓϦ։ൃऀ͚ͷϥΠϒ ϥϦཧπʔϧ CocoaPodsΛ͑؆୯ʹData API SDKΛΈࠐ
Ί·͢
platform :ios, '9.0' use_frameworks! target ‘MyApp’ do pod 'MTDataAPI-SDK' end
$ pod install
ϒϩάҰཡͷऔಘ
import MTDataAPI_SDK let api = DataAPI.sharedInstance api.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 if let items = result { print(items) } }, failure: { (error: JSON?) -> Void in }) }, failure: { (error: JSON?) -> Void in } )
هࣄͷ࡞
import MTDataAPI_SDK var entry: [String:String] = [:] entry["title"] = "title"
entry["body"] = "text" entry["status"] = "Publish" let api = DataAPI.sharedInstance api.APIBaseURL = "http://host/mt/mt-data-api.cgi" 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.sharedInstance api.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(siteID: siteID, 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 } )
ศརͳϥΠϒϥϦ
SDWebImage
SDWebImage ը૾ΛඇಉظͰμϯϩʔυ Ωϟογϡͯ͘͠Ε·͢ HTMLͱҧͬͯϒϥβ͕ྑ͖ʹܭΒͬͯ ͘Εͳ͍ͷͰ
imageView.sd_setImage(with: imageUrl)
SVProgressHUD
SVProgressHUD σʔλૹ৴࣌ͳͲʹΠϯδέʔλΛදࣔ͢ Δ ॲཧʹ͕͔͔࣌ؒΔ࣌ʹදࣔͯ͠ಈ͍ͯΔ ΑʂΞϐʔϧ
දࣔɿ SVProgressHUD.show(withStatus: “Loading…”) ඇදࣔɿ SVProgressHUD.dismiss()
pod 'SDWebImage' pod 'SVProgressHUD'
Data APIͰ͕Δੈք
Messenger෩
Έ Movable Typeͷهࣄ = νϟοτϧʔϜ هࣄͷίϝϯτ = ൃݴ
ݟͤํ͕ҧ͏͚ͩ هࣄͷίϝϯτΛ͍ͯ͠Δ͚ͩ ݟͤํʹΑͬͯνϟοτʹʂ
JSQMessagesViewController Φʔϓϯιʔεͷνϟο τUIϥΠϒϥϦ https://github.com/jessesquires/ JSQMessagesViewController
ϝοηʔδૹ৴
var comment = [String:String]() comment["body"] = text inputToolbar?.contentView?.rightBarButtonItem?.isEnabled = false
api.authentication(USERNAME, password: PASSWORD, remember: true, success:{ [weak self] _ in guard let me = self else { return } me.api.createCommentForEntry( siteID: me.SITE_ID, entryID: me.ENTRY_ID, comment: comment, success: {(result: JSON?)-> Void in me.inputToolbar?.contentView?.rightBarButtonItem?.isEnabled = true me.finishSendingMessage(animated: true) me.receiveMessage() }, failure: {(error: JSON?)-> Void in me.inputToolbar?.contentView?.rightBarButtonItem?.isEnabled = true } ) }, failure: {(error: JSON?)-> Void in self.inputToolbar?.contentView?.rightBarButtonItem?.isEnabled = true } )
ϝοηʔδड৴
let options = [ "limit":"100", "no_text_filter":"1", "fields":"author,body" ] api.authentication(USERNAME, password:
PASSWORD, remember: true, success:{ [weak self] _ in guard let me = self else { return } me.api.listCommentsForEntry( siteID: me.SITE_ID, entryID: me.ENTRY_ID, options: options, success: {(items:[JSON]?, total:Int?)-> Void in guard let items = items else { return } me.messagesFromJSON(items) }, failure: {(error: JSON?)-> Void in } ) }, failure: {(error: JSON?)-> Void in } )
σϞ
ڵຯͷ͋Δํ https://github.com/cheebow/MTChatApp ϓϩδΣΫτ͕μϯϩʔυͰ͖·͢
Ϙέͯ෩
Ϙέͯ ࣸਅͰҰݴϘέΔΣϒαʔϏε http://bokete.jp
͓ߘ ͓ʹը૾ ը૾ΛΞοϓϩʔυ uploadAssetForSite
͓બ ը૾Ұཡ͔Βը૾Λબͤ͞Δ listAssets getAsset
Ϙέߘ هࣄͷλΠτϧʹϘέ هࣄͷຊจʹબ͓ͨ͠ʹը૾(imgλά) هࣄͷΞΠςϜʹબ͓ͨ͠ʹΞΠςϜ هࣄߘ createEntry
var entry: [String: Any] = [:] entry["title"] = "Ϙέ" entry["body"]
= "<img src=\"http://localhost/photo.jpg\">" entry["assets"] = [[“id": 1]] entry["status"] = "Publish" let api = DataAPI.sharedInstance api.APIBaseURL = "http://host/mt/mt-data-api.cgi" 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 } )
ίϝϯτߘ هࣄͷίϝϯτ createCommentForEntry
Movable Type for iOS
Movable Type for iOS ී௨ͷϒϩάߘπʔϧ ͔͠͠ߘUI͕ಠࣗͰ͢
ϒϩοΫΤσΟλ
ϒϩοΫΤσΟλ ը૾ͱจষͷϒϩοΫΛฒସ͑ͯهࣄΛ ࡞ iOSͷখ͞ͳը໘Ͱهࣄ࡞Λָʹ
͍͢͞ͷͨΊʹ ཧը໘ͷൃʹनΘΕͳ͍ iOSͳΒͰͷUI Data APIͳΒ࣮ݱͰ͖·͢
MTͷཁ API༻࣌ͷ࠶ߏஙෆཁΦϓγϣϯ͕͋Δͱ ͍͍ͳʂ ͬͱAPI͕ߴʹͳΔͱ͍͍ͳʂ PUSH௨͕ૹΕΔΑ͏ʹͳΔͱ͍͍ͳʂ
·ͱΊ Data APIͱiOSΛΈ߹ΘͤΔͱ͍Ζ͍Ζָ͠ ͍͜ͱ͕Ͱ͖ͦ͏ʂ MTͷཧը໘͔Βࣗ༝ʹͳΔʂ ৽͍͠Ϣʔβମݧʂ
iOSΞϓϦ։ൃ iOSΞϓϦͷ։ൃෑډ͕ߴ͍͔…… ͦΜͳ࣌ɺͥͻɺΤϜϩδοΫגࣜձࣾ ʹ͓͍߹Θ͍ͤͩ͘͞ʂ
࣭ٙԠ
͓͠·͍