Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable building for visionOS #7394

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -104,7 +104,7 @@ jobs:
strategy:
matrix:
xcode:
- /Applications/Xcode_15.0.1.app
- /Applications/Xcode_15.3.0.app
steps:
- run: sudo xcode-select --switch ${{ matrix.xcode }}
- uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-ios.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: macos-14
timeout-minutes: 30
steps:
- run: sudo xcode-select --switch /Applications/Xcode_15.0.1.app
- run: sudo xcode-select --switch /Applications/Xcode_15.3.0.app
- uses: actions/setup-node@v3
with:
node-version: 18.x
Expand Down
10 changes: 8 additions & 2 deletions ios/Capacitor/Capacitor.xcodeproj/project.pbxproj
Expand Up @@ -962,12 +962,15 @@
MODULEMAP_FILE = Capacitor/Capacitor.modulemap;
PRODUCT_BUNDLE_IDENTIFIER = com.capacitorjs.ios.Capacitor;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = xros;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand All @@ -991,11 +994,14 @@
MODULEMAP_FILE = Capacitor/Capacitor.modulemap;
PRODUCT_BUNDLE_IDENTIFIER = com.capacitorjs.ios.Capacitor;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = xros;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down
6 changes: 6 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Expand Up @@ -63,9 +63,11 @@ import Cordova
loadWebView()
}

#if os(iOS)
override open func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, withSender sender: Any) -> Bool {
return false
}
#endif

// MARK: - Initialization

Expand Down Expand Up @@ -222,17 +224,21 @@ import Cordova
}

open func setStatusBarVisible(_ isStatusBarVisible: Bool) {
#if os(iOS)
self.isStatusBarVisible = isStatusBarVisible
UIView.animate(withDuration: 0.2, animations: {
self.setNeedsStatusBarAppearanceUpdate()
})
#endif
}

open func setStatusBarStyle(_ statusBarStyle: UIStatusBarStyle) {
#if os(iOS)
self.statusBarStyle = statusBarStyle
UIView.animate(withDuration: 0.2, animations: {
self.setNeedsStatusBarAppearanceUpdate()
})
#endif
}

open func setStatusBarAnimation(_ statusBarAnimation: UIStatusBarAnimation) {
Expand Down
10 changes: 10 additions & 0 deletions ios/Capacitor/Capacitor/CapacitorBridge.swift
Expand Up @@ -59,7 +59,11 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {

public var statusBarVisible: Bool {
get {
#if os(iOS)
return !(viewController?.prefersStatusBarHidden ?? true)
#else
return true
#endif
}
set {
DispatchQueue.main.async { [weak self] in
Expand All @@ -70,7 +74,11 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {

public var statusBarStyle: UIStatusBarStyle {
get {
#if os(iOS)
return viewController?.preferredStatusBarStyle ?? .default
#else
return .default
#endif
}
set {
DispatchQueue.main.async { [weak self] in
Expand Down Expand Up @@ -714,10 +722,12 @@ open class CapacitorBridge: NSObject, CAPBridgeProtocol {
if viewControllerToPresent.modalPresentationStyle == .popover {
self.viewController?.present(viewControllerToPresent, animated: flag, completion: completion)
} else {
#if os(iOS)
self.tmpWindow = UIWindow.init(frame: UIScreen.main.bounds)
self.tmpWindow?.rootViewController = TmpViewController.init()
self.tmpWindow?.makeKeyAndVisible()
self.tmpWindow?.rootViewController?.present(viewControllerToPresent, animated: flag, completion: completion)
#endif
}
}

Expand Down
14 changes: 14 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/CapacitorUrlRequest.swift
Expand Up @@ -12,6 +12,8 @@ open class CapacitorUrlRequest: NSObject, URLSessionTaskDelegate {
request = URLRequest(url: url)
request.httpMethod = method
headers = [:]

#if os(iOS)
if let lang = Locale.autoupdatingCurrent.languageCode {
if let country = Locale.autoupdatingCurrent.regionCode {
headers["Accept-Language"] = "\(lang)-\(country),\(lang);q=0.5"
Expand All @@ -20,6 +22,18 @@ open class CapacitorUrlRequest: NSObject, URLSessionTaskDelegate {
}
request.addValue(headers["Accept-Language"]!, forHTTPHeaderField: "Accept-Language")
}
#endif

#if os(visonOS)
markemer marked this conversation as resolved.
Show resolved Hide resolved
if let lang = Locale.autoupdatingCurrent.language.languageCode?.identifier {
if let country = Locale.autoupdatingCurrent.region?.identifier {
headers["Accept-Language"] = "\(lang)-\(country),\(lang);q=0.5"
} else {
headers["Accept-Language"] = "\(lang);q=0.5"
}
request.addValue(headers["Accept-Language"]!, forHTTPHeaderField: "Accept-Language")
}
#endif
}

public func getRequestDataAsJson(_ data: JSValue) throws -> Data? {
Expand Down
Expand Up @@ -404,7 +404,9 @@
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.ios.CapacitorCordova;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Debug;
};
Expand All @@ -424,7 +426,9 @@
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.ios.CapacitorCordova;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = "1,2,7";
};
name = Release;
};
Expand Down