AppDelegate.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2018 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 "AppDelegate.h"
  17. #import "ViewController.h"
  18. #import <FirebaseCore/FIRApp.h>
  19. #import <FirebaseCore/FIROptions.h>
  20. #import <FirebaseDynamicLinks/FIRDynamicLinks.h>
  21. @implementation AppDelegate
  22. - (BOOL)application:(UIApplication *)application
  23. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  24. [FIRApp configure];
  25. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  26. UINavigationController *navController = [[UINavigationController alloc]
  27. initWithRootViewController:[[ViewController alloc] initWithNibName:nil bundle:nil]];
  28. self.window.rootViewController = navController;
  29. [self.window makeKeyAndVisible];
  30. #ifdef DEBUG
  31. [FIRDynamicLinks performDiagnosticsWithCompletion:nil];
  32. #endif // DEBUG
  33. return YES;
  34. }
  35. - (BOOL)application:(UIApplication *)app
  36. openURL:(NSURL *)url
  37. options:(NSDictionary<NSString *, id> *)options {
  38. FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
  39. if (dynamicLink) {
  40. [self _showDynamicLinkInfo:dynamicLink];
  41. }
  42. return YES;
  43. }
  44. - (BOOL)application:(UIApplication *)application
  45. openURL:(NSURL *)url
  46. sourceApplication:(NSString *)sourceApplication
  47. annotation:(id)annotation {
  48. return [self application:application openURL:url options:@{}];
  49. }
  50. - (BOOL)application:(UIApplication *)application
  51. continueUserActivity:(NSUserActivity *)userActivity
  52. restorationHandler:
  53. #if __has_include(<UIKit/UIUserActivity.h>)
  54. (void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
  55. #else
  56. (void (^)(NSArray *))restorationHandler {
  57. #endif
  58. BOOL handled = [[FIRDynamicLinks dynamicLinks]
  59. handleUniversalLink:userActivity.webpageURL
  60. completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
  61. [self _showDynamicLinkInfo:dynamicLink];
  62. }];
  63. if (!handled) {
  64. // Show the deep link URL from userActivity.
  65. NSLog(@"Unhandled link %@", userActivity.webpageURL);
  66. }
  67. return handled;
  68. }
  69. - (void)_showDynamicLinkInfo:(FIRDynamicLink *)dynamicLink {
  70. NSLog(@"Got dynamic link %@", dynamicLink);
  71. UIAlertController *alertVC = [UIAlertController
  72. alertControllerWithTitle:@"Got Dynamic Link!"
  73. message:[NSString stringWithFormat:
  74. @"URL [%@], matchType [%ld], minimumAppVersion [%@]",
  75. dynamicLink.url, (unsigned long)dynamicLink.matchType,
  76. dynamicLink.minimumAppVersion]
  77. preferredStyle:UIAlertControllerStyleAlert];
  78. [alertVC addAction:[UIAlertAction actionWithTitle:@"Dismiss"
  79. style:UIAlertActionStyleCancel
  80. handler:NULL]];
  81. [self.window.rootViewController presentViewController:alertVC animated:YES completion:NULL];
  82. }
  83. @end