DemoAppDelegate.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2016 Google Inc. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GoogleMapsDemos/DemoAppDelegate.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. #import "GoogleMapsDemos/MasterViewController.h"
  18. #import "GoogleMapsDemos/SDKDemoAPIKey.h"
  19. @implementation DemoAppDelegate {
  20. id _services;
  21. }
  22. @synthesize window = _window;
  23. - (BOOL)application:(UIApplication *)application
  24. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  25. NSLog(@"Build version: %s", __VERSION__);
  26. if (kAPIKey.length == 0) {
  27. // Blow up if APIKey has not yet been set.
  28. NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
  29. NSString *format = @"Configure APIKey inside SDKDemoAPIKey.h for your "
  30. @"bundle `%@`, see README.GoogleMapsDemos for more information";
  31. @throw [NSException exceptionWithName:@"DemoAppDelegate"
  32. reason:[NSString stringWithFormat:format, bundleId]
  33. userInfo:nil];
  34. }
  35. [GMSServices provideAPIKey:kAPIKey];
  36. _services = [GMSServices sharedServices];
  37. // Log the required open source licenses! Yes, just NSLog-ing them is not enough but is good for
  38. // a demo.
  39. NSLog(@"Open source licenses:\n%@", [GMSServices openSourceLicenseInfo]);
  40. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  41. MasterViewController *master = [[MasterViewController alloc] init];
  42. master.appDelegate = self;
  43. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  44. // This is an iPhone; configure the top-level navigation controller as the
  45. // rootViewController, which contains the 'master' list of samples.
  46. self.navigationController =
  47. [[UINavigationController alloc] initWithRootViewController:master];
  48. // Force non-translucent navigation bar for consistency of demo between
  49. // iOS 6 and iOS 7.
  50. self.navigationController.navigationBar.translucent = NO;
  51. self.window.rootViewController = self.navigationController;
  52. } else {
  53. // This is an iPad; configure a split-view controller that contains the
  54. // the 'master' list of samples on the left side, and the current displayed
  55. // sample on the right (begins empty).
  56. UINavigationController *masterNavigationController =
  57. [[UINavigationController alloc] initWithRootViewController:master];
  58. UIViewController *empty = [[UIViewController alloc] init];
  59. UINavigationController *detailNavigationController =
  60. [[UINavigationController alloc] initWithRootViewController:empty];
  61. // Force non-translucent navigation bar for consistency of demo between
  62. // iOS 6 and iOS 7.
  63. detailNavigationController.navigationBar.translucent = NO;
  64. self.splitViewController = [[UISplitViewController alloc] init];
  65. self.splitViewController.delegate = master;
  66. self.splitViewController.viewControllers =
  67. @[masterNavigationController, detailNavigationController];
  68. self.splitViewController.presentsWithGesture = NO;
  69. self.window.rootViewController = self.splitViewController;
  70. }
  71. [self.window makeKeyAndVisible];
  72. return YES;
  73. }
  74. - (void)setSample:(UIViewController *)sample {
  75. NSAssert([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad,
  76. @"Expected device to be iPad inside setSample:");
  77. // Finds the UINavigationController in the right side of the sample, and
  78. // replace its displayed controller with the new sample.
  79. UINavigationController *nav =
  80. [self.splitViewController.viewControllers objectAtIndex:1];
  81. [nav setViewControllers:[NSArray arrayWithObject:sample] animated:NO];
  82. }
  83. - (UIViewController *)sample {
  84. NSAssert([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad,
  85. @"Expected device to be iPad inside sample");
  86. // The current sample is the top-most VC in the right-hand pane of the
  87. // splitViewController.
  88. UINavigationController *nav =
  89. [self.splitViewController.viewControllers objectAtIndex:1];
  90. return [[nav viewControllers] objectAtIndex:0];
  91. }
  92. @end