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

iPhoneアプリの通信エラー処理を考える

ninjinkun
January 26, 2012

 iPhoneアプリの通信エラー処理を考える

iPhoneアプリの通信エラー処理についての考察と実装。サンプルはこちら https://github.com/ninjinkun/AlertResume

ninjinkun

January 26, 2012
Tweet

More Decks by ninjinkun

Other Decks in Technology

Transcript

  1. iPhoneΞϓϦͷ௨৴Τϥʔॲཧ id:ninjinkun / @ninjinkun

  2. ͸͡Ίʹ • ೥຤ʹiOS Advent CalendarʹࢀՃ͠·ͨ͠ • 25೔·Ͱຖ೔೔ସΘΓͰهࣄΛॻ͘ • http://atnd.org/events/22792 •

    http://ninjinkun.hatenablog.com/entry/2011/12/23/224918
  3. ͸͡Ίʹ • ௨৴Τϥʔॲཧͷઃܭ • έʔεελσΟ • ࣮૷

  4. ௨৴͸ࣦഊ͢Δ ௨৴Τϥʔॲཧͷઃܭ • ಺ଂIO→͍͍ͩͨ੒ޭ͢Δ΋ͷͱࢥͬͯઃܭͯ͠Δ • ༰ྔΦʔόʔɺϑΝΠϧ໊ॏෳetc… • ௨৴IO→ࣦഊ͢ΔՄೳੑΛߟྀͯ͠ઃܭ͢Δ • iPhone͸ϞόΠϧσόΠε

    • ௨৴͸ߴ͍֬཰Ͱࣦഊ͢Δ • ลڥɺτϯωϧɺetc… • ҟৗܥͰ͸ͳ͘ਖ਼ৗܥͷҰ෦ͱͯ͠ଊ͑Δ
  5. ཧ૝తͳΤϥʔॲཧ ௨৴Τϥʔॲཧͷઃܭ • Ғ͍ਓᐌ͘… ΤϥʔϝοηʔδϘοΫε͸ɺϓϩάϥϜ͕όΧͳͷͰॲཧΛఀࢭ ͢Δͱ͍͍ͬͯΔΑ͏ͳ΋ͷͰ͋Γɺආ͚ͳ͚Ε͹ͳΒͳ͍ Τϥʔϝοηʔδʹ͸ɺڀۃͷΞΠϩχʔ͕͋ΔɻϢʔβʔ͕Τ ϥʔΛ൜͢ͷΛ๷͍Ͱ͸͘Εͳ͍ͷͩɻ

  6. ཧ૝తͳΤϥʔॲཧ ௨৴Τϥʔॲཧͷઃܭ • Ғ͍ਓᐌ͘… ΤϥʔμΠΞϩά͸ɺඞͣྱّਖ਼͘͠ɺΘ͔Γ΍͘͢໰୊఺Λࣔ ͠ɺ໾ʹཱͭ΋ͷͰͳ͚Ε͹ͳΒͳ͍ɻ Ϣʔβʔʹඞཁͳ৘ใΛఏڙ্ͨ͠ͰɺඞͣҰͭ͸ղܾࡦΛఏࣔͤ Α

  7. Τϥʔॲཧϓϥϯ ௨৴Τϥʔॲཧͷઃܭ দ Ϣʔβʔͷૢ࡞ΛΠϯλϥϓτͤͣʹϨδϡʔϜ͢Δ ஛ Ϣʔβʔͷૢ࡞ΛΠϯλϥϓτͯ͠ϨδϡʔϜ͢Δ ക ΤϥʔϝοηʔδΛදࣔ͢Δ͚ͩ

  8. έʔεελσΟ • Mail • Instagram • Facebook • Path

  9. Mail έʔεελσΟ • ࣦഊͯ͠΋ϝοηʔδϘοΫεʹೖΔ • ΞϓϦ͕ऴྃͯ͠΋όοΫάϥ΢ϯυͰ উखʹϨδϡʔϜ • OS૊ΈࠐΈ͔ͩΒͰ͖Δ͜ͱ •

    Ϣʔβʔ͕ΤϥʔΛҙࣝ͠ͳͯ͘΋ྑ͘ͳ͍ͬͯΔ • দϓϥϯ
  10. Instagram έʔεελσΟ • ΞοϓϩʔυΩϡʔ͕࣮૷͞Ε͍ͯΔ • ࣦഊ͢ΔͱϨδϡʔϜͰ͖Δ • ෳ਺ͷࣸਅΛϨδϡʔϜՄೳ • Ϣʔβʔ͕ࣗྗͰϨδϡʔϜ͢Δ࡞ۀ͸ඞཁ

    • ஛ϓϥϯ
  11. Facebook έʔεελσΟ • ௨৴͕ࣦഊͯ͠΋Կ΋ݴΘͳ͍ • ͻͲ͍

  12. Path έʔεελσΟ • ࣦഊͯ͠΋੒ޭͨ͠Α͏ʹݟ͍ͤͯΔ • ޙ͔Β௨৴͕ܨ͕Ε͹࠶౓ૹ৴ʢࣗಈʣ • ୯ͳΔPOST / GETͰ͸ͳ͘σʔλΛಉظ͍ͯ͠Δ(?)

    • ϢʔβʔʹΤϥʔΛҙࣝͤ͞ͳ͍ • দϓϥϯ • ͦͷ൓໘ૹ৴͕׬͍ྃͯ͠ͳ͍͜ͱʹ͸ؾ͔ͮͳ͍…
  13. ࣮૷ • Τϥʔͷදࣔ • UIAlertView • ϨδϡʔϜॲཧ • UIViewControllerͷ෮ݩ •

    Ωϡʔ https://github.com/ninjinkun/AlertResume
  14. Τϥʔͷදࣔ ࣮૷ • UIAlertView • NSErrorͱڠௐͤ͞Δͱศར • NSAlertViewʹ͸NSErrorΛҾ਺ʹऔΔίϯετϥΫλ ͕ଘࡏ͍ͯͨ͠ •

    …Ͱ͢ΑͶʁ
  15. Τϥʔͷදࣔ ࣮૷ • NSErrorʹ͸දࣔ༻ͷύϥϝʔ λ͕ἧ͍ͬͯΔ • શͯuserInfoͷσʔλ΁ͷ γϣʔτΧοτ • localizedDiscription

    • localizedFailureReason • localizedRecoverySuggestion • localizedRecoveryOptions
  16. Τϥʔͷදࣔ ࣮૷ NSArray *buttons = [NSArray arrayWithObjects:@"Ωϟϯηϧ", @"࠶ࢼߦ͢Δ", nil]; NSDictionary

    *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: @"ωοτϫʔΫΤϥʔ͕ൃੜ͠·ͨ͠", NSLocalizedDescriptionKey, @”ωοτϫʔΫʹ઀ଓͰ͖·ͤΜ”, NSLocalizedFailureReasonErrorKey, @"઀ଓΛ֬ೝͯ͠…", NSLocalizedRecoverySuggestionErrorKey, buttons, NSLocalizedRecoveryOptionsErrorKey, nil]; NSError*error = [NSError errorWithDomain:@"com.hoge.fuga" code:100 userInfo:userInfo];
  17. Τϥʔͷදࣔ ࣮૷ • UIAlertViewʹ৯Θͤͯදࣔ͢Δ @implementation UIAlertView (NSErrorAddition) -(id)initWithError:(NSError *)error {

    self = [super init]; if (self) { self.title = [error localizedDescription]; self.message = [[NSArray arrayWithObjects:[error localizedFailureReason], [error localizedRecoverySuggestion], nil] componentsJoinedByString:@"\n"]; NSArray* optionTitles = [error localizedRecoveryOptions]; for (NSString *title in optionTitles) { [self addButtonWithTitle:title]; } } return self; } @end
  18. ϨδϡʔϜॲཧ ࣮૷ • ViewController͝ͱϨδϡʔϜ • POSTͷը໘Λ΋͏Ұ౓։͖·͢ • ϨδϡʔϜૢ࡞͕௚ײత • ༧ظ͠ͳ͍ͱ͜ΖͰViewController͕։͍ͯ͠·͏

  19. ϨδϡʔϜॲཧ ࣮૷ • ΩϡʔͰϨδϡʔϜ • ϦΫΤετΛΩϡʔʹอଘ͓ͯ͘͠ • ੒ޭͨ͠ΒΩϡʔ͔Β͸࡟আ • ࣦഊͨ͠ΒΩϡʔͷϏϡʔ͔Β࠶ࢼߦૢ࡞Λߦ͏

    • ΩϡʔΛϓϨϏϡʔ͢ΔϏϡʔΛ࡞Δඞཁ༗Γ
  20. ·ͱΊ • ௨৴Τϥʔॲཧͷํ๏ʹ͍ͭͯߟ࡯ͨ͠ • ௨৴Τϥʔ͸ਖ਼ৗܥͷҰ෦ͱͯ͠ߟ͑Α͏ • ༷ʑͳΞϓϦͷέʔεΛ؍࡯ͨ͠ • Path͸͕Μ͹͍ͬͯΔ •

    ௨৴ΤϥʔॲཧΛ࣮૷ͯ͠Έͨ • UIAlertView • ϨδϡʔϜॲཧ2छྨ • େม͚ͩͲ͕Μ͹Γ·͠ΐ͏
  21. ࠷ۙग़ͨ͜ͷຊ͕݁ߏྑ͍ͱࢥͬͯ·͢ ͓·͚ • iOSϓϩάϥϛϯά ୈ2൛ • ΞʔϩϯŋώϨΨε, δϣʔɾίϯ΢ΣΠ