ActionCodeSettings.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import FirebaseCoreInternal
  15. import Foundation
  16. // TODO(Swift 6 Breaking): Consider breaking up into a checked Sendable Swift
  17. // type and unchecked Sendable ObjC wrapper class.
  18. /// Used to set and retrieve settings related to handling action codes.
  19. @objc(FIRActionCodeSettings) open class ActionCodeSettings: NSObject,
  20. @unchecked Sendable {
  21. /// This URL represents the state/Continue URL in the form of a universal link.
  22. ///
  23. /// This URL can should be constructed as a universal link that would either directly open
  24. /// the app where the action code would be handled or continue to the app after the action code
  25. /// is handled by Firebase.
  26. @objc(URL) open var url: URL? {
  27. get { impl.url.value() }
  28. set { impl.url.withLock { $0 = newValue } }
  29. }
  30. /// Indicates whether the action code link will open the app directly or after being
  31. /// redirected from a Firebase owned web widget.
  32. @objc open var handleCodeInApp: Bool {
  33. get { impl.handleCodeInApp.value() }
  34. set { impl.handleCodeInApp.withLock { $0 = newValue } }
  35. }
  36. /// The iOS bundle ID, if available. The default value is the current app's bundle ID.
  37. @objc open var iOSBundleID: String? {
  38. get { impl.iOSBundleID.value() }
  39. set { impl.iOSBundleID.withLock { $0 = newValue } }
  40. }
  41. /// The Android package name, if available.
  42. @objc open var androidPackageName: String? {
  43. get { impl.androidPackageName.value() }
  44. set { impl.androidPackageName.withLock { $0 = newValue } }
  45. }
  46. /// The minimum Android version supported, if available.
  47. @objc open var androidMinimumVersion: String? {
  48. get { impl.androidMinimumVersion.value() }
  49. set { impl.androidMinimumVersion.withLock { $0 = newValue } }
  50. }
  51. /// Indicates whether the Android app should be installed on a device where it is not available.
  52. @objc open var androidInstallIfNotAvailable: Bool {
  53. get { impl.androidInstallIfNotAvailable.value() }
  54. set { impl.androidInstallIfNotAvailable.withLock { $0 = newValue } }
  55. }
  56. /// The Firebase Dynamic Link domain used for out of band code flow.
  57. #if !FIREBASE_CI
  58. @available(
  59. *,
  60. deprecated,
  61. message: "Firebase Dynamic Links is deprecated. Migrate to use Firebase Hosting link and use `linkDomain` to set a custom domain instead."
  62. )
  63. #endif // !FIREBASE_CI
  64. @objc open var dynamicLinkDomain: String? {
  65. get { impl.dynamicLinkDomain.value() }
  66. set { impl.dynamicLinkDomain.withLock { $0 = newValue } }
  67. }
  68. /// The out of band custom domain for handling code in app.
  69. @objc public var linkDomain: String? {
  70. get { impl.linkDomain.value() }
  71. set { impl.linkDomain.withLock { $0 = newValue } }
  72. }
  73. private let impl: SendableActionCodeSettings
  74. /// Sets the iOS bundle ID.
  75. @objc override public init() {
  76. impl = .init()
  77. }
  78. /// Sets the Android package name, the flag to indicate whether or not to install the app,
  79. /// and the minimum Android version supported.
  80. ///
  81. /// If `installIfNotAvailable` is set to `true` and the link is opened on an android device, it
  82. /// will try to install the app if not already available. Otherwise the web URL is used.
  83. /// - Parameters:
  84. /// - androidPackageName: The Android package name.
  85. /// - installIfNotAvailable: Indicates whether or not the app should be installed if not
  86. /// available.
  87. /// - minimumVersion: The minimum version of Android supported.
  88. @objc open func setAndroidPackageName(_ androidPackageName: String,
  89. installIfNotAvailable: Bool,
  90. minimumVersion: String?) {
  91. impl
  92. .setAndroidPackageName(
  93. androidPackageName,
  94. installIfNotAvailable: installIfNotAvailable,
  95. minimumVersion: minimumVersion
  96. )
  97. }
  98. /// Sets the iOS bundle ID.
  99. open func setIOSBundleID(_ bundleID: String) {
  100. impl.setIOSBundleID(bundleID)
  101. }
  102. }
  103. private extension ActionCodeSettings {
  104. /// Checked Sendable implementation of `ActionCodeSettings`.
  105. final class SendableActionCodeSettings: Sendable {
  106. let url = FIRAllocatedUnfairLock<URL?>(initialState: nil)
  107. let handleCodeInApp = FIRAllocatedUnfairLock<Bool>(initialState: false)
  108. let iOSBundleID: FIRAllocatedUnfairLock<String?>
  109. let androidPackageName = FIRAllocatedUnfairLock<String?>(initialState: nil)
  110. let androidMinimumVersion = FIRAllocatedUnfairLock<String?>(initialState: nil)
  111. let androidInstallIfNotAvailable = FIRAllocatedUnfairLock<Bool>(initialState: false)
  112. #if !FIREBASE_CI
  113. @available(
  114. *,
  115. deprecated,
  116. message: "Firebase Dynamic Links is deprecated. Migrate to use Firebase Hosting link and use `linkDomain` to set a custom domain instead."
  117. )
  118. #endif // !FIREBASE_CI
  119. let dynamicLinkDomain = FIRAllocatedUnfairLock<String?>(initialState: nil)
  120. let linkDomain = FIRAllocatedUnfairLock<String?>(initialState: nil)
  121. init() {
  122. iOSBundleID = FIRAllocatedUnfairLock<String?>(initialState: Bundle.main.bundleIdentifier)
  123. }
  124. func setAndroidPackageName(_ androidPackageName: String,
  125. installIfNotAvailable: Bool,
  126. minimumVersion: String?) {
  127. self.androidPackageName.withLock { $0 = androidPackageName }
  128. androidInstallIfNotAvailable.withLock { $0 = installIfNotAvailable }
  129. androidMinimumVersion.withLock { $0 = minimumVersion }
  130. }
  131. func setIOSBundleID(_ bundleID: String) {
  132. iOSBundleID.withLock { $0 = bundleID }
  133. }
  134. }
  135. }