ApplicationDelegate.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/FIRConfiguration.h>
  19. #import <FBSDKCoreKit/FBSDKCoreKit.h>
  20. #import "AuthProviders.h"
  21. #import <FirebaseAuth/FirebaseAuth.h>
  22. #import "GTMSessionFetcherLogging.h"
  23. #import "MainViewController.h"
  24. /** @var gOpenURLDelegate
  25. @brief The delegate to for application:openURL:... method.
  26. */
  27. static __weak id<OpenURLDelegate> gOpenURLDelegate;
  28. @implementation ApplicationDelegate {
  29. // The main view controller of the sample app.
  30. MainViewController *_sampleAppMainViewController;
  31. }
  32. + (void)setOpenURLDelegate:(nullable id<OpenURLDelegate>)openURLDelegate {
  33. gOpenURLDelegate = openURLDelegate;
  34. }
  35. - (BOOL)application:(UIApplication *)application
  36. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  37. [GTMSessionFetcher setLoggingEnabled:YES];
  38. [[FIRConfiguration sharedInstance] setLoggerLevel:FIRLoggerLevelInfo];
  39. // Configure the default Firebase application:
  40. [FIRApp configure];
  41. [[FBSDKApplicationDelegate sharedInstance] application:application
  42. didFinishLaunchingWithOptions:launchOptions];
  43. // Load and present the UI:
  44. UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  45. _sampleAppMainViewController =
  46. [[MainViewController alloc] initWithNibName:NSStringFromClass([MainViewController class])
  47. bundle:nil];
  48. _sampleAppMainViewController.navigationItem.title = @"Firebase Auth";
  49. window.rootViewController = [[UINavigationController alloc]
  50. initWithRootViewController:_sampleAppMainViewController];
  51. self.window = window;
  52. [self.window makeKeyAndVisible];
  53. return YES;
  54. }
  55. - (BOOL)application:(nonnull UIApplication *)application
  56. openURL:(nonnull NSURL *)url
  57. options:(nonnull NSDictionary<NSString *, id> *)options {
  58. [[FBSDKApplicationDelegate sharedInstance] application:application
  59. openURL:url
  60. options:options];
  61. return [self application:application
  62. openURL:url
  63. sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
  64. annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  65. }
  66. - (BOOL)application:(UIApplication *)application
  67. openURL:(NSURL *)url
  68. sourceApplication:(NSString *)sourceApplication
  69. annotation:(id)annotation {
  70. if ([gOpenURLDelegate handleOpenURL:url sourceApplication:sourceApplication]) {
  71. return YES;
  72. }
  73. if ([_sampleAppMainViewController handleIncomingLinkWithURL:url]) {
  74. return YES;
  75. }
  76. return NO;
  77. }
  78. - (BOOL)application:(UIApplication *)application
  79. continueUserActivity:(NSUserActivity *)userActivity
  80. restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  81. if (userActivity.webpageURL) {
  82. return [_sampleAppMainViewController handleIncomingLinkWithURL:userActivity.webpageURL];
  83. }
  84. return NO;
  85. }
  86. @end