ApplicationDelegate.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2019 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 <FirebaseCore/FIRApp.h>
  18. #import <FirebaseCore/FIRLogger.h>
  19. #import "AuthProviders.h"
  20. #import "FirebaseAuth.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. _sampleAppMainViewController.navigationItem.title = @"Firebase Auth";
  46. window.rootViewController = [[UINavigationController alloc]
  47. initWithRootViewController:_sampleAppMainViewController];
  48. self.window = window;
  49. [self.window makeKeyAndVisible];
  50. return YES;
  51. }
  52. - (BOOL)application:(nonnull UIApplication *)application
  53. openURL:(nonnull NSURL *)url
  54. options:(nonnull NSDictionary<NSString *, id> *)options {
  55. return [self application:application
  56. openURL:url
  57. sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
  58. annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  59. }
  60. - (BOOL)application:(UIApplication *)application
  61. openURL:(NSURL *)url
  62. sourceApplication:(NSString *)sourceApplication
  63. annotation:(id)annotation {
  64. if ([gOpenURLDelegate handleOpenURL:url sourceApplication:sourceApplication]) {
  65. return YES;
  66. }
  67. if ([_sampleAppMainViewController handleIncomingLinkWithURL:url]) {
  68. return YES;
  69. }
  70. return NO;
  71. }
  72. - (BOOL)application:(UIApplication *)application
  73. continueUserActivity:(NSUserActivity *)userActivity
  74. restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  75. if (userActivity.webpageURL) {
  76. return [_sampleAppMainViewController handleIncomingLinkWithURL:userActivity.webpageURL];
  77. }
  78. return NO;
  79. }
  80. @end