ActionCodeSettings.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 out of band custom domain for handling code in app.
  57. @objc public var linkDomain: String? {
  58. get { impl.linkDomain.value() }
  59. set { impl.linkDomain.withLock { $0 = newValue } }
  60. }
  61. private let impl: SendableActionCodeSettings
  62. /// Sets the iOS bundle ID.
  63. @objc override public init() {
  64. impl = .init()
  65. }
  66. /// Sets the Android package name, the flag to indicate whether or not to install the app,
  67. /// and the minimum Android version supported.
  68. ///
  69. /// If `installIfNotAvailable` is set to `true` and the link is opened on an android device, it
  70. /// will try to install the app if not already available. Otherwise the web URL is used.
  71. /// - Parameters:
  72. /// - androidPackageName: The Android package name.
  73. /// - installIfNotAvailable: Indicates whether or not the app should be installed if not
  74. /// available.
  75. /// - minimumVersion: The minimum version of Android supported.
  76. @objc open func setAndroidPackageName(_ androidPackageName: String,
  77. installIfNotAvailable: Bool,
  78. minimumVersion: String?) {
  79. impl
  80. .setAndroidPackageName(
  81. androidPackageName,
  82. installIfNotAvailable: installIfNotAvailable,
  83. minimumVersion: minimumVersion
  84. )
  85. }
  86. /// Sets the iOS bundle ID.
  87. open func setIOSBundleID(_ bundleID: String) {
  88. impl.setIOSBundleID(bundleID)
  89. }
  90. }
  91. private extension ActionCodeSettings {
  92. /// Checked Sendable implementation of `ActionCodeSettings`.
  93. final class SendableActionCodeSettings: Sendable {
  94. let url = UnfairLock<URL?>(nil)
  95. let handleCodeInApp = UnfairLock<Bool>(false)
  96. let iOSBundleID: UnfairLock<String?>
  97. let androidPackageName = UnfairLock<String?>(nil)
  98. let androidMinimumVersion = UnfairLock<String?>(nil)
  99. let androidInstallIfNotAvailable = UnfairLock<Bool>(false)
  100. let linkDomain = UnfairLock<String?>(nil)
  101. init() {
  102. iOSBundleID = UnfairLock<String?>(Bundle.main.bundleIdentifier)
  103. }
  104. func setAndroidPackageName(_ androidPackageName: String,
  105. installIfNotAvailable: Bool,
  106. minimumVersion: String?) {
  107. self.androidPackageName.withLock { $0 = androidPackageName }
  108. androidInstallIfNotAvailable.withLock { $0 = installIfNotAvailable }
  109. androidMinimumVersion.withLock { $0 = minimumVersion }
  110. }
  111. func setIOSBundleID(_ bundleID: String) {
  112. iOSBundleID.withLock { $0 = bundleID }
  113. }
  114. }
  115. }