Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOSアプリでMTを256倍使う

CHEEBOW
January 14, 2017

 iOSアプリでMTを256倍使う

「【MT東京−31】バレンタインデー1ヶ月前から始める Swift×MT Data API」で行われたセッションの資料です

CHEEBOW

January 14, 2017
Tweet

More Decks by CHEEBOW

Other Decks in Programming

Transcript

  1. ָۂఏڙͨ͠ΞΠυϧ ເ຾ͶΉ ͰΜͺ૊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-  ܭ૊
  2. Mac

  3. float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; if (ver >=

    7.0) { [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; }
  4. let ver = (UIDevice.currentDevice().systemVersion as NSString).floatValue if ver >= 7.0

    { UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent }
  5. Data API Data API ʹ͍ͭͯ(https://www.sixapart.jp/movabletype/data-api/) “Data API ͸ɺ͞·͟·ͳϓϩάϥϜݴޠ͔Β REST/JSONํࣜͰ Movable

    Type ʹΞΫηε͠ɺσʔλͷऔಘ΍ߋ৽͕Ͱ͖ΔAPIͰɺMovable Type 6 ͔Β౥ ࡌ͞Ε͍ͯ·͢ɻ Data API Λ࢖͑͹ɺCMSͰ؅ཧ͍ͯ͠ΔσʔλΛɺαΠτ্Ͱࣗ༝ʹݺ ͼग़ͨ͠Γɺ·ͨɺಠࣗͷ؅ཧը໘΍ΞϓϦͷ։ൃ΍ɺଞͷϓϥοτ ϑΥʔϜͱͷ࿈ܞͳͲΛ༰қʹߦ͏͜ͱ͕Ͱ͖·͢ɻ”
  6. 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 } )
  7. 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 } )
  8. 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 } )
  9. 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 } )
  10. 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 } )
  11. 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 } )