SceneDelegate.m 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2020 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 "SceneDelegate.h"
  17. #import <FirebaseDynamicLinks/FIRDynamicLinks.h>
  18. @interface SceneDelegate ()
  19. @end
  20. @implementation SceneDelegate
  21. - (void)scene:(UIScene *)scene
  22. willConnectToSession:(UISceneSession *)session
  23. options:(UISceneConnectionOptions *)connectionOptions {
  24. // Use this method to optionally configure and attach the UIWindow `window` to the provided
  25. // UIWindowScene `scene`. If using a storyboard, the `window` property will automatically be
  26. // initialized and attached to the scene. This delegate does not imply the connecting scene or
  27. // session are new (see `application:configurationForConnectingSceneSession` instead).
  28. }
  29. - (void)sceneDidDisconnect:(UIScene *)scene {
  30. // Called as the scene is being released by the system.
  31. // This occurs shortly after the scene enters the background, or when its session is discarded.
  32. // Release any resources associated with this scene that can be re-created the next time the scene
  33. // connects. The scene may re-connect later, as its session was not neccessarily discarded (see
  34. // `application:didDiscardSceneSessions` instead).
  35. }
  36. - (void)sceneDidBecomeActive:(UIScene *)scene {
  37. // Called when the scene has moved from an inactive state to an active state.
  38. // Use this method to restart any tasks that were paused (or not yet started) when the scene was
  39. // inactive.
  40. }
  41. - (void)sceneWillResignActive:(UIScene *)scene {
  42. // Called when the scene will move from an active state to an inactive state.
  43. // This may occur due to temporary interruptions (ex. an incoming phone call).
  44. }
  45. - (void)sceneWillEnterForeground:(UIScene *)scene {
  46. // Called as the scene transitions from the background to the foreground.
  47. // Use this method to undo the changes made on entering the background.
  48. }
  49. - (void)sceneDidEnterBackground:(UIScene *)scene {
  50. // Called as the scene transitions from the foreground to the background.
  51. // Use this method to save data, release shared resources, and store enough scene-specific state
  52. // information to restore the scene back to its current state.
  53. }
  54. - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
  55. BOOL handled = [[FIRDynamicLinks dynamicLinks]
  56. handleUniversalLink:userActivity.webpageURL
  57. completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
  58. [self _showDynamicLinkInfo:dynamicLink];
  59. }];
  60. if (!handled) {
  61. // Show the deep link URL from userActivity.
  62. NSLog(@"Unhandled link %@", userActivity.webpageURL);
  63. }
  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