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

    View full-size slide

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

    View full-size slide

  3. ͸͡Ίʹ
    • ௨৴Τϥʔॲཧͷઃܭ
    • έʔεελσΟ
    • ࣮૷

    View full-size slide

  4. ௨৴͸ࣦഊ͢Δ
    ௨৴Τϥʔॲཧͷઃܭ
    • ಺ଂIO→͍͍ͩͨ੒ޭ͢Δ΋ͷͱࢥͬͯઃܭͯ͠Δ
    • ༰ྔΦʔόʔɺϑΝΠϧ໊ॏෳetc…
    • ௨৴IO→ࣦഊ͢ΔՄೳੑΛߟྀͯ͠ઃܭ͢Δ
    • iPhone͸ϞόΠϧσόΠε
    • ௨৴͸ߴ͍֬཰Ͱࣦഊ͢Δ
    • ลڥɺτϯωϧɺetc…
    • ҟৗܥͰ͸ͳ͘ਖ਼ৗܥͷҰ෦ͱͯ͠ଊ͑Δ

    View full-size slide

  5. ཧ૝తͳΤϥʔॲཧ
    ௨৴Τϥʔॲཧͷઃܭ
    • Ғ͍ਓᐌ͘…
    ΤϥʔϝοηʔδϘοΫε͸ɺϓϩάϥϜ͕όΧͳͷͰॲཧΛఀࢭ
    ͢Δͱ͍͍ͬͯΔΑ͏ͳ΋ͷͰ͋Γɺආ͚ͳ͚Ε͹ͳΒͳ͍
    Τϥʔϝοηʔδʹ͸ɺڀۃͷΞΠϩχʔ͕͋ΔɻϢʔβʔ͕Τ
    ϥʔΛ൜͢ͷΛ๷͍Ͱ͸͘Εͳ͍ͷͩɻ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  12. Path
    έʔεελσΟ
    • ࣦഊͯ͠΋੒ޭͨ͠Α͏ʹݟ͍ͤͯΔ
    • ޙ͔Β௨৴͕ܨ͕Ε͹࠶౓ૹ৴ʢࣗಈʣ
    • ୯ͳΔPOST / GETͰ͸ͳ͘σʔλΛಉظ͍ͯ͠Δ(?)
    • ϢʔβʔʹΤϥʔΛҙࣝͤ͞ͳ͍
    • দϓϥϯ
    • ͦͷ൓໘ૹ৴͕׬͍ྃͯ͠ͳ͍͜ͱʹ͸ؾ͔ͮͳ͍…

    View full-size slide

  13. ࣮૷
    • Τϥʔͷදࣔ
    • UIAlertView
    • ϨδϡʔϜॲཧ
    • UIViewControllerͷ෮ݩ
    • Ωϡʔ
    https://github.com/ninjinkun/AlertResume

    View full-size slide

  14. Τϥʔͷදࣔ
    ࣮૷
    • UIAlertView
    • NSErrorͱڠௐͤ͞Δͱศར
    • NSAlertViewʹ͸NSErrorΛҾ਺ʹऔΔίϯετϥΫλ
    ͕ଘࡏ͍ͯͨ͠
    • …Ͱ͢ΑͶʁ

    View full-size slide

  15. Τϥʔͷදࣔ
    ࣮૷
    • NSErrorʹ͸දࣔ༻ͷύϥϝʔ
    λ͕ἧ͍ͬͯΔ
    • શͯuserInfoͷσʔλ΁ͷ
    γϣʔτΧοτ
    • localizedDiscription
    • localizedFailureReason
    • localizedRecoverySuggestion
    • localizedRecoveryOptions

    View full-size slide

  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];

    View full-size slide

  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

    View full-size slide

  18. ϨδϡʔϜॲཧ
    ࣮૷
    • ViewController͝ͱϨδϡʔϜ
    • POSTͷը໘Λ΋͏Ұ౓։͖·͢
    • ϨδϡʔϜૢ࡞͕௚ײత
    • ༧ظ͠ͳ͍ͱ͜ΖͰViewController͕։͍ͯ͠·͏

    View full-size slide

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

    View full-size slide

  20. ·ͱΊ
    • ௨৴Τϥʔॲཧͷํ๏ʹ͍ͭͯߟ࡯ͨ͠
    • ௨৴Τϥʔ͸ਖ਼ৗܥͷҰ෦ͱͯ͠ߟ͑Α͏
    • ༷ʑͳΞϓϦͷέʔεΛ؍࡯ͨ͠
    • Path͸͕Μ͹͍ͬͯΔ
    • ௨৴ΤϥʔॲཧΛ࣮૷ͯ͠Έͨ
    • UIAlertView
    • ϨδϡʔϜॲཧ2छྨ
    • େม͚ͩͲ͕Μ͹Γ·͠ΐ͏

    View full-size slide

  21. ࠷ۙग़ͨ͜ͷຊ͕݁ߏྑ͍ͱࢥͬͯ·͢
    ͓·͚
    • iOSϓϩάϥϛϯά ୈ2൛
    • ΞʔϩϯŋώϨΨε, δϣʔɾίϯ΢ΣΠ

    View full-size slide