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

iOSで無限バックグラウンドアップロード(に挑戦してみた話)

ainame
March 12, 2015

 iOSで無限バックグラウンドアップロード(に挑戦してみた話)

ainame

March 12, 2015
Tweet

More Decks by ainame

Other Decks in Programming

Transcript

  1. i O S Ͱ ແ ݶ ό ο Ϋ ά

    ϥ ΢ ϯ υ Ξ ο ϓ ϩ ʔ υ ʢ ʹ ௅ ઓ ͯ͠ Έ ͨ ࿩ ʣ P o t a t o t i p s # 1 5 2 0 1 5 - 0 3 - 1 2
  2. @ a i n a m e R u b

    y / A W S / i O S ࣗ ݾ ঺ հ
  3. Α ͘ ͋ Δ Ξϧό Ϝ Ξ ϓ Ϧ •

    ίϝϯτΛ͚ͭͯࣸਅΛΞοϓϩʔυʢ1ճ1ຕʣ • ϐοΧʔͰը૾Λબ୒ͯ͠ΔͱݱΕΔʮˎҰ౓ʹΞο ϓϩʔυग़དྷΔຕ਺͸Nຕ·ͰͰ͢ʯ • ϑΥΞάϥ΢ϯυͰͷΞοϓϩʔυ͕લఏ
  4. ࡞ Γ ͨ ͍ Ξϧό Ϝ Ξ ϓ Ϧ •

    ϐοΧʔͰը૾Λࢦఆ͢ΔͱΞοϓϩʔυ͕࢝·Δ • ΞϓϦΛดͯ͡΋όοΫάϥ΢ϯυͰ׬ྃͤ͞Δ • όοΫάϥ΢ϯυͰແݶʹΞοϓϩʔυ
  5. ό ο Ϋ ά ϥ ΢ ϯ υ Ͱ ௨

    ৴ • NSURLSessionΛҎԼΛ૊Έ߹Θͤͯ࢖͏ • NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: • NSURLSession uploadTaskWithRequest:fromFile: • Ҿ਺ʹNSURLͰ౉ͨ͠ϑΝΠϧύεͷϑΝΠϧΛHTTPϦΫΤε τͷBodyʹ٧Ίͯapplication/octet-streamͰPOST • όοΫάϥ΢ϯυͰ΋Ξοϓϩʔυॲཧ͕ܧଓՄೳΒ͠ ͍ɾɾɾʁ
  6. Ӭ ଓ Խ J O B Ω ϡ ʔ •

    EDQueueͱ͍͏ϥΠϒϥϦΛࢀߟʹಠ࣮ࣗ૷ • https://github.com/thisandagain/queue • FMDB+SQLiteͰӬଓԽ • લͷJob͕ऴྃͨ͠Β࣍ͷJobΛऔΓग़࣮ͯ͠ߦ͢Δ
  7. ࣮ ࡍ ʹ ࢼ ͯ͠ Έ ͨ • ͔֬ʹΞοϓϩʔυग़དྷΔɾɾɾʂ •

    ͍͢͝ɾɾɾʂ • ΍ͬͨɾɾɾʂ׬੒΍ɾɾɾʂ • ͔͠͠ɺDeploygateܦ༝Ͱ࢖ͬͯ΋Β͏ͱಈ͔ͳ ͍ɾɾɾʂʁʂʁʂʁ
  8. ໰ ୊ ൃ ੜ • NSURLSessionConfiguration discretionaryͷυΩϡϝϯτΛಡΜͰΈΔ • > When

    transferring large amounts of data, you are encouraged to set the value of this property to YES. Doing so lets the system schedule those transfers at times that are more optimal for the device. For example, the system might delay transferring large files until the device is plugged in and connected to the network via Wi- Fi. The default value of this property is NO. • ཁ໿: ୺຤͕Lightningέʔϒϧʹܨ͕͍ͬͯͯWi-FiΛར༻͢Δ·Ͱ େ͖ͳϑΝΠϧͷసૹΛ଴ͭ • https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSessionConfiguration_class/ index.html#//apple_ref/occ/instp/NSURLSessionConfiguration/discretionary
  9. ࠶ ࣮ ૷ • Silent Remote NotificationΛར༻͢Δ • {aps: {content-available:1}}Λ͚ͭΔ

    • Push௨஌Λड͚औΔͱ30ඵఔ౓όοΫάϥ΢ϯυͰ ॲཧ͕࣮ߦͰ͖Δ • Ξοϓϩʔυ -> Push௨஌-> Ξοϓϩʔυ -> …
 Ͱ͏·͍͘͘ͷͰ͸ɾɾɾʁ
  10. · ͱ Ί • iOSͰόοΫάϥ΢ϯυॲཧʹ͸੍ݶ͕͋Δ • Background Transfer͸ʢ࢖͍͜ͳ͢ͷʣ೉͍͠ • ҰఆִؒͰSilent

    Remote NotificationૹΕ͹
 ແݶΞοϓϩʔυ΋Մೳ!!! • ࣮ࡍʹ͸Push௨஌ʹ͸ඇެ։࢓༷ͰϨʔτϦϛοτ ͕͋ΔͷͰແݶͰ͸ͳ͍ͱͷ͜ͱཁݕূʢ௥هʣ