SDKDemoAppDelegate.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/SDKDemoAppDelegate.h"
  5. #import "SDKDemos/SDKDemoAPIKey.h"
  6. #import "SDKDemos/SDKDemoMasterViewController.h"
  7. #import <GoogleMaps/GoogleMaps.h>
  8. @implementation SDKDemoAppDelegate {
  9. id services_;
  10. }
  11. @synthesize window = _window;
  12. - (BOOL)application:(UIApplication *)application
  13. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  14. NSLog(@"Build verison: %d", __apple_build_version__);
  15. if ([kAPIKey length] == 0) {
  16. // Blow up if APIKey has not yet been set.
  17. NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
  18. NSString *format = @"Configure APIKey inside SDKDemoAPIKey.h for your "
  19. @"bundle `%@`, see README.GoogleMapsSDKDemos for more information";
  20. @throw [NSException exceptionWithName:@"SDKDemoAppDelegate"
  21. reason:[NSString stringWithFormat:format, bundleId]
  22. userInfo:nil];
  23. }
  24. [GMSServices provideAPIKey:kAPIKey];
  25. services_ = [GMSServices sharedServices];
  26. // Log the required open source licenses! Yes, just NSLog-ing them is not
  27. // enough but is good for a demo.
  28. NSLog(@"Open source licenses:\n%@", [GMSServices openSourceLicenseInfo]);
  29. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  30. SDKDemoMasterViewController *master = [[SDKDemoMasterViewController alloc] init];
  31. master.appDelegate = self;
  32. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  33. // This is an iPhone; configure the top-level navigation controller as the
  34. // rootViewController, which contains the 'master' list of samples.
  35. self.navigationController =
  36. [[UINavigationController alloc] initWithRootViewController:master];
  37. // Force non-translucent navigation bar for consistency of demo between
  38. // iOS 6 and iOS 7.
  39. self.navigationController.navigationBar.translucent = NO;
  40. self.window.rootViewController = self.navigationController;
  41. } else {
  42. // This is an iPad; configure a split-view controller that contains the
  43. // the 'master' list of samples on the left side, and the current displayed
  44. // sample on the right (begins empty).
  45. UINavigationController *masterNavigationController =
  46. [[UINavigationController alloc] initWithRootViewController:master];
  47. UIViewController *empty = [[UIViewController alloc] init];
  48. UINavigationController *detailNavigationController =
  49. [[UINavigationController alloc] initWithRootViewController:empty];
  50. // Force non-translucent navigation bar for consistency of demo between
  51. // iOS 6 and iOS 7.
  52. detailNavigationController.navigationBar.translucent = NO;
  53. self.splitViewController = [[UISplitViewController alloc] init];
  54. self.splitViewController.delegate = master;
  55. self.splitViewController.viewControllers =
  56. @[masterNavigationController, detailNavigationController];
  57. self.splitViewController.presentsWithGesture = NO;
  58. self.window.rootViewController = self.splitViewController;
  59. }
  60. [self.window makeKeyAndVisible];
  61. return YES;
  62. }
  63. - (void)setSample:(UIViewController *)sample {
  64. NSAssert([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad,
  65. @"Expected device to be iPad inside setSample:");
  66. // Finds the UINavigationController in the right side of the sample, and
  67. // replace its displayed controller with the new sample.
  68. UINavigationController *nav =
  69. [self.splitViewController.viewControllers objectAtIndex:1];
  70. [nav setViewControllers:[NSArray arrayWithObject:sample] animated:NO];
  71. }
  72. - (UIViewController *)sample {
  73. NSAssert([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad,
  74. @"Expected device to be iPad inside sample");
  75. // The current sample is the top-most VC in the right-hand pane of the
  76. // splitViewController.
  77. UINavigationController *nav =
  78. [self.splitViewController.viewControllers objectAtIndex:1];
  79. return [[nav viewControllers] objectAtIndex:0];
  80. }
  81. @end