@capacitor/ios 9.0.0-alpha.7 → 9.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Package.swift ADDED
@@ -0,0 +1,78 @@
1
+ // swift-tools-version: 6.0
2
+ import PackageDescription
3
+
4
+ // DO NOT MODIFY THIS FILE - generated from the Package.swift in the Capacitor repository.
5
+ let package = Package(
6
+ name: "Capacitor",
7
+ platforms: [.iOS(.v16)],
8
+ products: [
9
+ .library(
10
+ name: "Capacitor",
11
+ targets: ["Capacitor", "CapacitorObjC", "CapacitorObjCShims"]
12
+ ),
13
+ .library(
14
+ name: "Cordova",
15
+ targets: ["Cordova"]
16
+ ),
17
+ .library(
18
+ name: "CapacitorCordova",
19
+ targets: ["Cordova", "CapacitorCordova"]
20
+ )
21
+ ],
22
+ targets: [
23
+ .target(
24
+ name: "CapacitorObjC",
25
+ path: "Sources/CapacitorObjC",
26
+ publicHeadersPath: "include",
27
+ cSettings: [
28
+ .headerSearchPath("include"),
29
+ .headerSearchPath("include/Capacitor")
30
+ ]
31
+ ),
32
+ .target(
33
+ name: "Capacitor",
34
+ dependencies: ["CapacitorObjC"],
35
+ path: "Sources/Capacitor",
36
+ resources: [
37
+ .copy("assets"),
38
+ .copy("PrivacyInfo.xcprivacy")
39
+ ],
40
+ swiftSettings: [.swiftLanguageMode(.v5)]
41
+ ),
42
+ .target(
43
+ name: "CapacitorObjCShims",
44
+ dependencies: ["Capacitor"],
45
+ path: "Sources/CapacitorObjCShims",
46
+ exclude: ["Capacitor.modulemap"],
47
+ publicHeadersPath: "include",
48
+ cSettings: [
49
+ .headerSearchPath("include"),
50
+ .headerSearchPath("include/Capacitor")
51
+ ]
52
+ ),
53
+ .target(
54
+ name: "Cordova",
55
+ path: "Sources/Cordova",
56
+ exclude: ["CapacitorCordova.modulemap"],
57
+ resources: [.copy("PrivacyInfo.xcprivacy")],
58
+ publicHeadersPath: "include",
59
+ cSettings: [
60
+ .headerSearchPath("include"),
61
+ .headerSearchPath("include/Cordova")
62
+ ],
63
+ linkerSettings: [
64
+ .linkedFramework("UIKit"),
65
+ .linkedFramework("WebKit"),
66
+ .linkedFramework("MobileCoreServices"),
67
+ .linkedFramework("CFNetwork")
68
+ ]
69
+ ),
70
+ .target(
71
+ name: "CapacitorCordova",
72
+ dependencies: ["Capacitor", "Cordova"],
73
+ path: "Sources/CapacitorCordova",
74
+ swiftSettings: [.swiftLanguageMode(.v5)]
75
+ )
76
+ ],
77
+ swiftLanguageModes: [.v5]
78
+ )
@@ -28,4 +28,69 @@ public class ApplicationDelegateProxy: NSObject, UIApplicationDelegate {
28
28
  ])
29
29
  return true
30
30
  }
31
+
32
+ /// The orientations the window's `CAPBridgeViewController` allows, including a `ScreenOrientation.lock()`.
33
+ ///
34
+ /// With the SwiftUI template the bridge is a child of the window's root view controller, so UIKit never asks it
35
+ /// for `supportedInterfaceOrientations`. Forward `application(_:supportedInterfaceOrientationsFor:)` from the
36
+ /// app delegate here so that the bridge's orientations still apply.
37
+ public func application(
38
+ _ application: UIApplication,
39
+ supportedInterfaceOrientationsFor window: UIWindow?
40
+ ) -> UIInterfaceOrientationMask {
41
+ Self.supportedInterfaceOrientations(for: window)
42
+ }
43
+
44
+ static func supportedInterfaceOrientations(for window: UIWindow?) -> UIInterfaceOrientationMask {
45
+ // An empty mask comes from `ScreenOrientation.lock('any')`, which the bridge stores as `.unknown`.
46
+ guard let rootViewController = window?.rootViewController,
47
+ let mask = bridgeViewController(in: rootViewController)?.supportedInterfaceOrientations,
48
+ !mask.isEmpty,
49
+ !isDecidedByPresentation(over: rootViewController, sharingNothingWith: mask)
50
+ else { return infoPlistInterfaceOrientations }
51
+ return mask
52
+ }
53
+
54
+ private static func isDecidedByPresentation(
55
+ over viewController: UIViewController,
56
+ sharingNothingWith mask: UIInterfaceOrientationMask
57
+ ) -> Bool {
58
+ var presented = viewController.presentedViewController
59
+ while let current = presented {
60
+ // A full-screen presentation decides its own orientations, as it does when the bridge is the root view
61
+ // controller. UIKit also asks `.custom` ones, so any that shares no orientation with the bridge decides
62
+ // too: returning the bridge's mask would leave UIKit with no orientation in common, which crashes.
63
+ if [.fullScreen, .overFullScreen].contains(current.modalPresentationStyle)
64
+ || current.supportedInterfaceOrientations.isDisjoint(with: mask) {
65
+ return true
66
+ }
67
+ presented = current.presentedViewController
68
+ }
69
+ return false
70
+ }
71
+
72
+ private static func bridgeViewController(in viewController: UIViewController) -> CAPBridgeViewController? {
73
+ if let bridgeViewController = viewController as? CAPBridgeViewController {
74
+ return bridgeViewController
75
+ }
76
+ return viewController.children.lazy.compactMap { bridgeViewController(in: $0) }.first
77
+ }
78
+
79
+ /// The orientations declared in Info.plist, which UIKit uses when the app delegate doesn't answer.
80
+ static var infoPlistInterfaceOrientations: UIInterfaceOrientationMask {
81
+ let info = Bundle.main.infoDictionary
82
+ let iPadNames = UIDevice.current.userInterfaceIdiom == .pad
83
+ ? info?["UISupportedInterfaceOrientations~ipad"] as? [String] : nil
84
+ let names = iPadNames ?? info?["UISupportedInterfaceOrientations"] as? [String] ?? []
85
+ let mask = names.reduce(into: UIInterfaceOrientationMask()) { mask, name in
86
+ switch name {
87
+ case "UIInterfaceOrientationPortrait": mask.insert(.portrait)
88
+ case "UIInterfaceOrientationPortraitUpsideDown": mask.insert(.portraitUpsideDown)
89
+ case "UIInterfaceOrientationLandscapeLeft": mask.insert(.landscapeLeft)
90
+ case "UIInterfaceOrientationLandscapeRight": mask.insert(.landscapeRight)
91
+ default: break
92
+ }
93
+ }
94
+ return mask.isEmpty ? .all : mask
95
+ }
31
96
  }
@@ -64,6 +64,7 @@ import WebKit
64
64
  override open func viewDidAppear(_ animated: Bool) {
65
65
  super.viewDidAppear(animated)
66
66
  NotificationCenter.default.post(Notification(name: .capacitorViewDidAppear))
67
+ SceneDelegateProxy.shared.bridgeViewDidAppear()
67
68
  if bridge?.config.hasInitialFocus ?? true {
68
69
  self.webView?.becomeFirstResponder()
69
70
  }
@@ -122,11 +122,6 @@ internal extension InstanceDescriptor {
122
122
  } else {
123
123
  #if DEBUG
124
124
  isWebDebuggable = true
125
- #else
126
- // this is needed for SPM xcframework Capacitor. Can eventually be removed when the SPM package moves to being source-based.
127
- if let debugValue = Bundle.main.object(forInfoDictionaryKey: "CAPACITOR_DEBUG") as? String, debugValue == "true" {
128
- isWebDebuggable = true
129
- }
130
125
  #endif
131
126
  }
132
127
  if let initialFocus = (config[keyPath: "ios.initialFocus"] as? Bool) ?? (config[keyPath: "initialFocus"] as? Bool) {
@@ -14,20 +14,16 @@ public class SceneDelegateProxy: NSObject, UISceneDelegate {
14
14
 
15
15
  public private(set) var lastURL: URL?
16
16
 
17
+ private var hasBridgeViewAppeared = false
18
+ private var pendingDeliveries: [() -> Void] = []
19
+
17
20
  public func scene(
18
21
  _ scene: UIScene, willConnectTo session: UISceneSession,
19
22
  options connectionOptions: UIScene.ConnectionOptions
20
23
  ) {
21
24
  NotificationCenter.default.post(name: .capacitorSceneWillConnect, object: scene)
22
25
 
23
- // Plugins haven't loaded yet on a cold start, so notifications posted here are
24
- // missed. Deliver them on the first capacitorViewDidAppear, once plugins are
25
- // registered.
26
- var token: NSObjectProtocol?
27
- token = NotificationCenter.default.addObserver(forName: .capacitorViewDidAppear, object: nil, queue: .main) { _ in
28
- if let token {
29
- NotificationCenter.default.removeObserver(token)
30
- }
26
+ deliver {
31
27
  if !connectionOptions.urlContexts.isEmpty {
32
28
  self.scene(scene, openURLContexts: connectionOptions.urlContexts)
33
29
  }
@@ -113,22 +109,25 @@ public class SceneDelegateProxy: NSObject, UISceneDelegate {
113
109
  public func handle(openURL: URL, scene: UIScene? = nil) {
114
110
  let targetScene = scene ?? Self.activeForegroundScene()
115
111
  lastURL = openURL
112
+ ApplicationDelegateProxy.shared.lastURL = openURL
116
113
  let options: [UIApplication.OpenURLOptionsKey: Any] = [:]
117
114
 
118
- // Capacitor 8 backwards compat
119
- NotificationCenter.default.post(
120
- name: .capacitorOpenURL,
121
- object: [
122
- "url": openURL,
123
- "options": options
124
- ])
115
+ deliver {
116
+ // Capacitor 8 backwards compat
117
+ NotificationCenter.default.post(
118
+ name: .capacitorOpenURL,
119
+ object: [
120
+ "url": openURL,
121
+ "options": options
122
+ ])
125
123
 
126
- NotificationCenter.default.post(
127
- name: .capacitorSceneOpenURL, object: targetScene,
128
- userInfo: [
129
- "url": openURL,
130
- "options": options
131
- ])
124
+ NotificationCenter.default.post(
125
+ name: .capacitorSceneOpenURL, object: targetScene,
126
+ userInfo: [
127
+ "url": openURL,
128
+ "options": options
129
+ ])
130
+ }
132
131
  }
133
132
 
134
133
  /// Routes a browsing-web `NSUserActivity` into Capacitor's universal-link handlers
@@ -166,19 +165,39 @@ public class SceneDelegateProxy: NSObject, UISceneDelegate {
166
165
  }
167
166
  let targetScene = scene ?? Self.activeForegroundScene()
168
167
  lastURL = url
168
+ ApplicationDelegateProxy.shared.lastURL = url
169
169
 
170
- // Capacitor 8 backwards compat
171
- NotificationCenter.default.post(
172
- name: .capacitorOpenUniversalLink,
173
- object: [
174
- "url": url
175
- ])
170
+ deliver {
171
+ // Capacitor 8 backwards compat
172
+ NotificationCenter.default.post(
173
+ name: .capacitorOpenUniversalLink,
174
+ object: [
175
+ "url": url
176
+ ])
176
177
 
177
- NotificationCenter.default.post(
178
- name: .capacitorSceneOpenUniversalLink, object: targetScene,
179
- userInfo: [
180
- "url": url
181
- ])
178
+ NotificationCenter.default.post(
179
+ name: .capacitorSceneOpenUniversalLink, object: targetScene,
180
+ userInfo: [
181
+ "url": url
182
+ ])
183
+ }
184
+ }
185
+
186
+ /// Called by `CAPBridgeViewController.viewDidAppear`. Until it runs, plugins are not
187
+ /// registered and a posted notification reaches nobody, so link deliveries are held.
188
+ func bridgeViewDidAppear() {
189
+ hasBridgeViewAppeared = true
190
+ let pending = pendingDeliveries
191
+ pendingDeliveries.removeAll()
192
+ pending.forEach { $0() }
193
+ }
194
+
195
+ private func deliver(_ work: @escaping () -> Void) {
196
+ if hasBridgeViewAppeared {
197
+ work()
198
+ } else {
199
+ pendingDeliveries.append(work)
200
+ }
182
201
  }
183
202
 
184
203
  private static func activeForegroundScene() -> UIWindowScene? {
@@ -26,10 +26,6 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
26
26
  #if DEBUG
27
27
  return true
28
28
  #else
29
- // this is needed for SPM xcframework Capacitor. Can eventually be removed when the SPM package moves to being source-based.
30
- if let debugValue = Bundle.main.object(forInfoDictionaryKey: "CAPACITOR_DEBUG") as? String, debugValue == "true" {
31
- return true
32
- }
33
29
  return false
34
30
  #endif
35
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/ios",
3
- "version": "9.0.0-alpha.7",
3
+ "version": "9.0.0-beta.0",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -13,6 +13,7 @@
13
13
  "url": "https://github.com/ionic-team/capacitor/issues"
14
14
  },
15
15
  "files": [
16
+ "Package.swift",
16
17
  "Sources/",
17
18
  "Capacitor.podspec",
18
19
  "CapacitorCordova.podspec",
@@ -24,7 +25,7 @@
24
25
  "xc:test": "cd .. && xcodebuild test -scheme Capacitor-Package -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.5' -collect-test-diagnostics never"
25
26
  },
26
27
  "peerDependencies": {
27
- "@capacitor/core": "^9.0.0-alpha.7"
28
+ "@capacitor/core": "^9.0.0-beta.0"
28
29
  },
29
30
  "publishConfig": {
30
31
  "access": "public"