0
I want to get notification like UIApplication.didBecomeActiveNotification and UIApplication.willResignActiveNotification when app switches in iPad Stage Controller Mode, but UIApplication.didBecomeActiveNotification, UIApplication.willResignActiveNotification just dont work, is there any method to get this notification
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I want to use a Map to show current location and heading, but the map first show, it just wont work. And when I switch off and switch on again, it works. codes below:
BackgroundMapView.swift
import SwiftUI
import MapKit
struct BackgroundMapView: View {
var scope: Namespace.ID?
private var cameraPosition: MapCameraPosition = .userLocation(
followsHeading: true,
fallback: .automatic
)
private var locations: [Location]
init(_ scope: Namespace.ID? = nil, locations: [Location]) {
self.scope = scope
self.locations = locations
}
var body: some View {
Map(
initialPosition: cameraPosition,
scope: scope
) {
MapPolyline(coordinates: locations.map({ $0.coordinate.toGCJ02 }))
.stroke(
.red,
lineWidth: 3
)
}
.mapControlVisibility(.hidden)
}
}
#Preview {
MainView()
}
HomeVIew.swift
import SwiftUI
struct HomeView: View {
@StateObject private var locationManager = LocationManager()
@State private var isMapEnabled = UserDefaults.isHomeMapEnabled {
didSet {
UserDefaults.isHomeMapEnabled = isMapEnabled
}
}
@Namespace private var mapScope
var body: some View {
if isMapEnabled {
BackgroundMapView(mapScope, locations: locationManager.locations)
.mapScope(mapScope)
}
}
}
Our iOS app, when running as an iOS App on Mac, crashes consistently under the following scenario:
1. Launch the app on an external display.
2. Minimize the app window.
3. Disconnect the external display.
The app crashes every time under these conditions. The crash log shows the following call stack:
*** Assertion failure in -[UINSWorkspace _maximumContentSizeForWindowOnScreen:], UINSWorkspace.m:401
-[UINSWorkspace _maximumContentSizeForWindowOnScreen:]: screen parameter should not be nil
(
0 CoreFoundation 0x000000018e841df0 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000018e306b60 objc_exception_throw + 88
2 Foundation 0x000000018fb6aa78 -[NSCalendarDate initWithCoder:] + 0
3 UIKitMacHelper 0x00000001a9a59110 -[UINSWorkspace _maximumContentSizeForWindowOnScreen:] + 184
4 UIKitMacHelper 0x00000001a9a3e748 -[UINSSceneViewController _usableScreenSizeWithSceneSize:shouldOverride:] + 412
5 UIKitMacHelper 0x00000001a9a3d55c -[UINSSceneViewController _effectiveScaleFactorForLayoutWithOverride:] + 88
6 UIKitMacHelper 0x00000001a9a3f3a8 -[UINSSceneViewController _updateZoomFactors] + 28
7 UIKitMacHelper 0x00000001a9a3f248 -[UINSSceneViewController _updateZoomFactorsAndDoLayout] + 24
8 UIKitMacHelper 0x00000001a9a3df80 -[UINSSceneViewController _doUpdates:] + 104
9 UIKitMacHelper 0x00000001a99ad460 -[UINSSceneViewController observeValueForKeyPath:ofObject:change:context:] + 176
10 Foundation 0x000000018facb0d8 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 388
11 Foundation 0x000000018facb0d8 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 388
12 Foundation 0x000000018fa8f7b4 NSKeyValueNotifyObserver + 252
13 Foundation 0x000000018fb3c560 NSKeyValueDidChange + 388
14 Foundation 0x00000001903149a0 NSKeyValueDidChangeWithPerThreadPendingNotifications + 160
15 AppKit 0x00000001924673d4 -[NSThemeFrame _didChangeContentLayoutRect] + 76
16 AppKit 0x000000019246521c -[NSWindow _oldPlaceWindow:fromServer:] + 744
)
It seems like the system attempts to access a screen object that is already nil after the external monitor is removed. This leads to an assertion failure in UINSWorkspace.
Is there any known workaround or update planned to address this issue?
Thank you.
Hello,
After upgrading to macOS 26.2, I’ve noticed a significant performance regression when calling evaluateJavaScript in an iOS App running on Mac (WKWebView, Swift project).
Observed behavior
On macOS 26.2, the callback of evaluateJavaScript takes around 3 seconds to return.
This happens not only for:
evaluateJavaScript("navigator.userAgent")
but also for simple or even empty scripts, for example:
evaluateJavaScript("")
On previous macOS versions, the same calls typically returned in ~200 ms.
Additional testing
I created a new, empty Objective-C project with a WKWebView and tested the same evaluateJavaScript calls.
In the Objective-C project, the callback still returns in ~200 ms, even on macOS 26.2.
Question
Is this a known issue or regression related to:
iOS Apps on Mac,
Swift + WKWebView, or
behavioral changes in evaluateJavaScript on macOS 26.2?
Any information about known issues, internal changes, or recommended workarounds would be greatly appreciated.
Thank you.
Test Code Swift
class ViewController: UIViewController {
private var tmpWebView: WKWebView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupUserAgent()
}
func setupUserAgent() {
let t1 = CACurrentMediaTime()
tmpWebView = WKWebView(frame: .zero)
tmpWebView?.isInspectable = true
tmpWebView?.evaluateJavaScript("navigator.userAgent") { [weak self] result, error in
let t2 = CACurrentMediaTime()
print("[getUserAgent] \(t2 - t1)s")
self?.tmpWebView = nil
}
}
}
Test Code Objective-C
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
WKWebView *webView = [[WKWebView alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{
[webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
NSTimeInterval endTime = [[NSDate date] timeIntervalSince1970];
NSLog(@"[getUserAgent]: %.2f s", (endTime - startTime));
}];
});
}