AppDelegate.m 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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:(void (^)(NSArray *))restorationHandler {
  53. BOOL handled = [[FIRDynamicLinks dynamicLinks]
  54. handleUniversalLink:userActivity.webpageURL
  55. completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
  56. [self _showDynamicLinkInfo:dynamicLink];
  57. }];
  58. if (!handled) {
  59. // Show the deep link URL from userActivity.
  60. NSLog(@"Unhandled link %@", userActivity.webpageURL);
  61. }
  62. return handled;
  63. }
  64. - (void)_showDynamicLinkInfo:(FIRDynamicLink *)dynamicLink {
  65. NSLog(@"Got dynamic link %@", dynamicLink);
  66. UIAlertController *alertVC = [UIAlertController
  67. alertControllerWithTitle:@"Got Dynamic Link!"
  68. message:[NSString stringWithFormat:
  69. @"URL [%@], matchType [%ld], minimumAppVersion [%@]",
  70. dynamicLink.url, (unsigned long)dynamicLink.matchType,
  71. dynamicLink.minimumAppVersion]
  72. preferredStyle:UIAlertControllerStyleAlert];
  73. [alertVC addAction:[UIAlertAction actionWithTitle:@"Dismiss"
  74. style:UIAlertActionStyleCancel
  75. handler:NULL]];
  76. [self.window.rootViewController presentViewController:alertVC animated:YES completion:NULL];
  77. }
  78. @end