JLRoutesについて

6139fd48daa26e786794598c4a6b546a?s=47 ninjinkun
March 12, 2014

 JLRoutesについて

6139fd48daa26e786794598c4a6b546a?s=128

ninjinkun

March 12, 2014
Tweet

Transcript

  1. +-3PVUFTʹ͍ͭͯ OJOKJOLVO

  2. J04ΞϓϦͱ63-εΩʔϜ w 8FCϖʔδ͔ΒΞϓϦΛىಈͯ͠ίϯςϯπΛදࣔ w ϩάΠϯॲཧͳͲͷϑϩʔͷҰ෦ w ଞΞϓϦͱͷ࿈ܞ 63-εΩʔϜ͕ඞཁʹͳΔ৔߹

  3. J04ΞϓϦͱ63-εΩʔϜ w εΩʔϜΛઃఆ ! w ύεΛύʔε w OKLTFBSDI w ΫΤϦΛύʔε

    w OKLTFBSDI RQPUBUPUJQT w ॲཧΛىಈ ॲཧͷྲྀΕ
  4. J04ΞϓϦͱ63-εΩʔϜ ࣮૷ྫ -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { if ([url.path isEqualToString:@“/search"])

    { NSString *searchQuery; NSArray *queries = [url.query componentsSeparatedByString:@"&"]; for (NSString *query in queries) { NSArray *keyValue = [query componentsSeparatedByString:@"="]; if (keyValue.count == 2) { if ([keyValue[0] isEqualToString:@"q"]) { searchQuery = keyValue[1]; // Search query found!! } } } ! SearchResultViewController *viewController = [[SearchResultViewController alloc] initWithQuery:query]; [self showViewController:viewController]; return YES; } } OKLTFBSDI RQPUBUPUJQT
  5. J04ΞϓϦͱ63-εΩʔϜ w ϧʔςΟϯάͷϧʔϧهड़ͱॲཧ͕෼཭͞Ε͍ͯͳ͍ w "QQ%FMFHBUFʹ΂ͨॻ͖͕ͪ͠ w JGจ͕ͲΜͲΜ૿͍͑ͯ͘ w ΫΤϦΛखͰύʔε͍ͯ͠Δ w

    /463-ʹ͸ΫΤϦΛߏ଄ମͱͯ͠औΓग़͢࢓૊Έ͕ ͳ͍ w ΈΜͳΦϨΦϨΫΤϦύʔαʔΛ࣋ͭΑ͏ʹͳΔ Կ͕໰୊͔
  6. J04ΞϓϦͱ63-εΩʔϜ w ύεʹม਺͕ೖ͍ͬͯΔͱݸผʹύʔε͢Δඞཁ͕͋ Δ w VTFSOJOKJOLVOQSPpMF w શ෦ΫΤϦʹೖΕͯ͘ΕʜΈ͍ͨͳؾ෼ʹͳͬͯΑ͘ ͳ͍ !

    w ʜͱ৭ʑ͋ͬͯมߋʹऑ͍ Կ͕໰୊͔
  7. +-3PVUFT w 63-ͷύλʔϯͱCMPDLTΛొ࿥ w 63-͕དྷͨΒCMPDLTΛىಈ w 4JOBUSB3PVUFSMJLFͳΠϯλʔϑΣΠε w ύϥϝʔλʔͷड͚౉͠ͳͲ΋αϙʔτ w

    IUUQTHJUIVCDPNKPFMEFW+-3PVUFT
  8. +-3PVUFT ࢖͍ํ JLRoutes *router = [JLRoutes routesForScheme:@“njk"]; ! [router addRoute:@"/search"

    handler:^BOOL(NSDictionary *parameters) { NSString *searchQuery = parameters[@“q"]; ! SearchResultViewController *viewController = [[SearchResultViewController alloc] initWithQuery:searchQuery]; [self showViewController:viewController]; return YES; }]; ! [router addRoute:@"/users/:user_id" handler:^BOOL(NSDictionary *parameters) { NSString *userId = parameters[@"user_id"]; ! UserViewController *viewController = [[UserViewController alloc] init]; viewController.userId = userId; [self showViewController:viewController]; return YES; }];
  9. +-3PVUFT w ϧʔςΟϯάϧʔϧͷొ࿥ͱ࣮ߦΛ෼཭Ͱ͖Δ ࢖͍ํ @implementation AppDelegate ! -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL

    *)url { JLRoutes *router = [JLRoutes routesForScheme:@"njk"]; return [router routeURL:url]; } ! @end
  10. ଞϥΠϒϥϦͱͷൺֱ w /JNCVT,JUTPDLJU w 4USJOH0CKFDU$PEJOHGPS0CKFDUJWF$ w จࣈྻͷύλʔϯ͔ΒΦϒδΣΫτͷੜ੒·Ͱ΍ͬͯ͘ΕΔ w SPVUBCMFJPT w

    63-6*7JFX$POUSPMMFS w ֎෦͔Β63-εΩʔϚΛىಈ͢Δ͜ͱ͸૝ఆ͍ͯ͠ͳͦ͞͏ w +-3PVUFT w 63-ͱCMPDLTͷσΟεύον͚ͩʹಛԽͯ͠γϯϓϧ
  11. ·ͱΊ w 63-εΩʔϜΛ࢖͏͜ͱ͕͋Ε͹+-3PVUFΦεεϝ w 4JOBUSB3PVUFSMJLFͳͷͰهड़͕γϯϓϧͰมߋ΋
 ؆୯

  12. ͓·͚
 9DPEF  "3$@45"/%"3% ໰୊

  13.  "3$@45"/%"3% ໰୊ w 9DPEF w "3$@45"/%"3%BSNWBSNWT w 9DPEF w

    "3$@45"/%"3%BSNWBSNWTBSN ! w CJUະରԠͷϥΠϒϥϦ͕͍ࠞͬͯ͟ΔͱϏϧυͰ ͖ͳ͍
  14.  "3$@45"/%"3% ໰୊ w खͰࢦఆ͢Δͱ$PDPB1PETͰ͚͜Δ ! ! ! ! w

    ෳ਺ͷ"3$)4ΛϋϯυϦϯάͰ͖ͳ͍όά ͕͋Δ $PDPB1PET
  15.  "3$@45"/%"3% ໰୊ w  45"/%"3%@"3$)@@#*5 Λ࢖͑͹ղܾ ! ! w

    ݁ہ͸CJUରԠ͕ਖ਼ಓ w ͓࢖͍ͷϥΠϒϥϦ͕CJUରԠ͢ΔΛ଴ͪ·͠ΐ͏ 4PMVUJPO
  16.  "3$@45"/%"3% ໰୊ 4PMVUJPO