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
660
Other Decks in Programming
See All in Programming
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
410
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
550
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.1k
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
380
Оптимизируем производительность блока Казначейство
lamodatech
0
740
php-conference-japan-2024
tasuku43
0
370
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
190
Recoilを剥がしている話
kirik
5
7.4k
return文におけるstd::moveについて
onihusube
1
1.3k
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
750
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
260
良いユニットテストを書こう
mototakatsu
10
3.3k
Featured
See All Featured
Done Done
chrislema
182
16k
Code Review Best Practice
trishagee
65
17k
Visualization
eitanlees
146
15k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Gamification - CAS2011
davidbonilla
80
5.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Building Adaptive Systems
keathley
38
2.3k
A Philosophy of Restraint
colly
203
16k
Agile that works and the tools we love
rasmusluckow
328
21k
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ΞϓϦͷ։ൃෑډ͕ߴ͍͔…… ͦΜͳ࣌ɺͥͻɺΤϜϩδοΫגࣜձࣾ ʹ͓͍߹Θ͍ͤͩ͘͞ʂ
࣭ٙԠ
͓͠·͍