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
630
Other Decks in Programming
See All in Programming
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
CSC509 Lecture 12
javiergs
PRO
0
160
Quine, Polyglot, 良いコード
qnighy
4
640
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
100
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
940
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
C++でシェーダを書く
fadis
6
4.1k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Featured
See All Featured
A better future with KSS
kneath
238
17k
What's new in Ruby 2.0
geeforr
343
31k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
The Invisible Side of Design
smashingmag
298
50k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Building an army of robots
kneath
302
43k
Thoughts on Productivity
jonyablonski
67
4.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Automating Front-end Workflow
addyosmani
1366
200k
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ΞϓϦͷ։ൃෑډ͕ߴ͍͔…… ͦΜͳ࣌ɺͥͻɺΤϜϩδοΫגࣜձࣾ ʹ͓͍߹Θ͍ͤͩ͘͞ʂ
࣭ٙԠ
͓͠·͍