ApplicationDelegate.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ApplicationDelegate.h"
  17. #import "AuthProviders.h"
  18. #import "FirebaseCommunity/FIRApp.h"
  19. #import "FirebaseAuth.h"
  20. #import "FirebaseCommunity/FIRLogger.h"
  21. #import "GTMSessionFetcherLogging.h"
  22. #import "MainViewController.h"
  23. /** @var gOpenURLDelegate
  24. @brief The delegate to for application:openURL:... method.
  25. */
  26. static __weak id<OpenURLDelegate> gOpenURLDelegate;
  27. @implementation ApplicationDelegate {
  28. // The main view controller of the sample app.
  29. MainViewController *_sampleAppMainViewController;
  30. }
  31. + (void)setOpenURLDelegate:(nullable id<OpenURLDelegate>)openURLDelegate {
  32. gOpenURLDelegate = openURLDelegate;
  33. }
  34. - (BOOL)application:(UIApplication *)application
  35. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  36. [GTMSessionFetcher setLoggingEnabled:YES];
  37. FIRSetLoggerLevel(FIRLoggerLevelInfo);
  38. // Configure the default Firebase application:
  39. [FIRApp configure];
  40. // Load and present the UI:
  41. UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  42. _sampleAppMainViewController =
  43. [[MainViewController alloc] initWithNibName:NSStringFromClass([MainViewController class])
  44. bundle:nil];
  45. window.rootViewController = _sampleAppMainViewController;
  46. self.window = window;
  47. [self.window makeKeyAndVisible];
  48. return YES;
  49. }
  50. - (BOOL)application:(nonnull UIApplication *)application
  51. openURL:(nonnull NSURL *)url
  52. options:(nonnull NSDictionary<NSString *, id> *)options {
  53. return [self application:application
  54. openURL:url
  55. sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
  56. annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  57. }
  58. - (BOOL)application:(UIApplication *)application
  59. openURL:(NSURL *)url
  60. sourceApplication:(NSString *)sourceApplication
  61. annotation:(id)annotation {
  62. if ([gOpenURLDelegate handleOpenURL:url sourceApplication:sourceApplication]) {
  63. return YES;
  64. }
  65. if ([_sampleAppMainViewController handleIncomingLinkWithURL:url]) {
  66. return YES;
  67. }
  68. return NO;
  69. }
  70. - (BOOL)application:(UIApplication *)application
  71. continueUserActivity:(NSUserActivity *)userActivity
  72. restorationHandler:(void (^)(NSArray *))restorationHandler {
  73. if (userActivity.webpageURL) {
  74. return [_sampleAppMainViewController handleIncomingLinkWithURL:userActivity.webpageURL];
  75. }
  76. return NO;
  77. }
  78. @end