AppDelegate.m 3.4 KB

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