AppDelegate.m 3.9 KB

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