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

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

45c0e67049c82c238143b82a1660a713?s=47 ainame
March 12, 2015

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

45c0e67049c82c238143b82a1660a713?s=128

ainame

March 12, 2015
Tweet

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. ஫ ҙ ʢ ௥ ه ʣ • ࠓճͷൃද͸iPhone/iOS/APNSͳͲʹυΩϡϝϯτʹ ͸هࡌ͞Ε͍ͯͳ͍ϒϥοΫϘοΫεͳ࢓༷ʹ͍ͭͯ ະݕূͷ෦෼͕͋ΔͷͰਖ਼֬Ͱ͸ͳ͍Ͱ͢

    • ൃදޙࢦఠ͍͍ͨͩͨͷͰҰ෦मਖ਼͠·ͨ͠
  3. @ a i n a m e R u b

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

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

    ϐοΧʔͰը૾Λࢦఆ͢ΔͱΞοϓϩʔυ͕࢝·Δ • ΞϓϦΛดͯ͡΋όοΫάϥ΢ϯυͰ׬ྃͤ͞Δ • όοΫάϥ΢ϯυͰແݶʹΞοϓϩʔυ
  7. ՝ ୊ • iOSΞϓϦ͸όοΫάϥ΢ϯυॲཧ͕ωοΫ • 3෼ͷ੍ݶ͕͋Δ • iOS7Ͱ௥Ճ͞ΕͨNSURLSessionͷbackgroundػೳ࢖͑ͦ͏ • ӬଓԽ͞ΕͨJobΩϡʔ͕ඞཁͦ͏

    • NSOperationQueueͩͱϝϞϦʹ͔͠σʔλͷΒͳ͍ͷͰ ΞϓϦดͨ͡Βࢮ͵
  8. ό ο Ϋ ά ϥ ΢ ϯ υ Ͱ ௨

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

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

    ͍͢͝ɾɾɾʂ • ΍ͬͨɾɾɾʂ׬੒΍ɾɾɾʂ • ͔͠͠ɺDeploygateܦ༝Ͱ࢖ͬͯ΋Β͏ͱಈ͔ͳ ͍ɾɾɾʂʁʂʁʂʁ
  11. ໰ ୊ ൃ ੜ • 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
  12. ࠶ ࣮ ૷ • Silent Remote NotificationΛར༻͢Δ • {aps: {content-available:1}}Λ͚ͭΔ

    • Push௨஌Λड͚औΔͱ30ඵఔ౓όοΫάϥ΢ϯυͰ ॲཧ͕࣮ߦͰ͖Δ • Ξοϓϩʔυ -> Push௨஌-> Ξοϓϩʔυ -> …
 Ͱ͏·͍͘͘ͷͰ͸ɾɾɾʁ
  13. Ϋ ϥ Π Ξ ϯ τ α ʔόʔ ը ૾

  14. Ϋ ϥ Π Ξ ϯ τ α ʔόʔ P U

    S H ௨ ஌
  15. · ͱ Ί • iOSͰόοΫάϥ΢ϯυॲཧʹ͸੍ݶ͕͋Δ • Background Transfer͸ʢ࢖͍͜ͳ͢ͷʣ೉͍͠ • ҰఆִؒͰSilent

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