In my macOS app I'm encoding and restoring the state of a view between app launches. It used to work fine until I updated to macOS 14 and Xcode 15. Now Xcode logs this error when calling coder.decodeObject(forKey: "string"):
*** -[NSPersistentUIKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x1dfa40918) [/System/Library/Frameworks/Foundation.framework]' for key 'string', even though it was not explicitly included in the client allowed classes set: '{(
)}'. This will be disallowed in the future.
The following sample code reproduces the issue:
class ViewController: NSViewController {
override func viewDidAppear() {
invalidateRestorableState()
}
override class func allowedClasses(forRestorableStateKeyPath keyPath: String) -> [AnyClass] {
return [NSString.self]
}
override func encodeRestorableState(with coder: NSCoder) {
coder.encode("asdf", forKey: "string")
}
override func restoreState(with coder: NSCoder) {
print(coder.decodeObject(forKey: "string") as! String)
}
}
What am I doing wrong?
Post
Replies
Boosts
Views
Activity
I cannot find in the documentation if using NEFilterDataProvider.apply(_:) has any advantage over manually inspecting incoming flows in handleNewFlow(_:) other than being a shortcut. Or are those rules guaranteed to be applied even if the network extension crashes or similar? If it has no practical advantages, then manually inspecting each flow allows to set up more flexible dynamic rules.
I keep getting crash reports in Xcode for one of my macOS apps published on the App Store. Actually it's not the main app that crashes, but the embedded Finder Sync extension. The crash reports indicate that this source code line
static var appGroupSaveDirectoryUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: identifier)!.appendingPathComponent("Library/Application Support/somedata")
crashes with error
Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0 (<compiler-generated>:0)
That line is a static variable defined in a class that is included in the main app as well as the Finder extension.
The documentation reads
In iOS, the value is nil when the group identifier is invalid. In macOS, a URL of the expected form is always returned, even if the app group is invalid
If the documentation says that the method call can never be nil, why am I getting this crash? Is it a bug or is the documentation wrong, or am I doing something wrong? And why does the Finder Sync extension crash and not the main app? I cannot reproduce this crash with the App Store app or within Xcode and Console shows no crash reports for the app on my Mac.
I'm using this code to get the path of an executable from the audit token provided in NEFilterDataProvider.handleNewFlow(_:), forwarded from the Network Extension to the main app via IPC:
private func securePathFromAuditToken(_ auditToken: Data) throws -> String {
let secFlags = SecCSFlags()
var secCode: SecCode?
var status = SecCodeCopyGuestWithAttributes(nil, [kSecGuestAttributeAudit: auditToken] as CFDictionary, secFlags, &secCode)
guard let secCode = secCode else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
var secStaticCode: SecStaticCode?
status = SecCodeCopyStaticCode(secCode, secFlags, &secStaticCode)
guard let secStaticCode = secStaticCode else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
var url: CFURL?
status = SecCodeCopyPath(secStaticCode, secFlags, &url)
guard let url = url as URL? else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
return url.path
}
This code sometimes returns paths like /System/Library/PrivateFrameworks/HelpData.framework/Versions/A/Resources/helpd or /Library/Developer/CoreSimulator/Volumes/iOS_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd.
But sometimes the SecCodeCopyGuestWithAttributes fails with status 100001 which is defined in MacErrors.h as kPOSIXErrorEPERM = 100001, /* Operation not permitted */. In these cases I resort to this code, which I have read is not as secure:
private func insecurePathFromAuditToken(_ auditToken: Data) throws -> String? {
if auditToken.count == MemoryLayout<audit_token_t>.size {
let pid = auditToken.withUnsafeBytes { buffer in
audit_token_to_pid(buffer.baseAddress!.assumingMemoryBound(to: audit_token_t.self).pointee)
}
let pathbuf = UnsafeMutablePointer<Int8>.allocate(capacity: Int(PROC_PIDPATHINFO_SIZE))
defer {
pathbuf.deallocate()
}
let ret = proc_pidpath(pid, pathbuf, UInt32(PROC_PIDPATHINFO_SIZE))
if ret <= 0 {
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno))
}
return String(cString: pathbuf)
}
return nil
}
This insecure code then returns paths like /usr/libexec/trustd, /usr/libexec/rapportd, /usr/libexec/nsurlsessiond and /usr/libexec/timed.
From what I can see, SecCodeCopyGuestWithAttributes fails for all processes in /usr/libexec. Some of these processes have executables with the same name placed in another directory, like /Library/Developer/CoreSimulator/Volumes/iOS_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd for which it succeeds, while for /usr/libexec/mobileassetd it fails.
Occasionally, both the secure and the insecure methods fail and in these cases the secure one returns status code 100003, which is defined as kPOSIXErrorESRCH = 100003, /* No such process */. When can this happen?
This seems to happen with both NEFilterFlow.sourceAppAuditToken and sourceProcessAuditToken. What is the problem?
In a Simulator instance running iOS 15, I am able to tap and hold an app in the Dock and drag it to the left or right screen border to create a new window of that app. But when doing that in a Simulator instance running iOS 16 or 17, after tap and holding an app in the Dock, I cannot drag it anywhere, it just stays in the Dock. Is this a bug or is there another solution?
I'm trying to copy some files from the Finder on macOS 14 to several Simulator instances running iOS 16 and 17. When I right-click the file in the Finder, I can select Share > Simulator, then a share dialog pops up where I select the relevant Simulator and click on Send. According to this official help topic, the Files app should open allowing me to choose the destination, but instead nothing happens and the shared file is nothing to be seen. What's the issue?
When using NSTextLayoutManager.addRenderingAttribute(.backgroundColor, value: NSColor.red, for: range), the background color for a line is only drawn as far as the last visible character. There is also a thin space between the lines where the background color is not visible.
Whe using NSLayoutManager.addTemporaryAttribute(.backgroundColor, value: NSColor.red, forCharacterRange: range), the background color is drawn also for newline characters and soft line wraps.
I would like to achieve the effect of using NSLayoutManager.addTemporaryAttribute(.backgroundColor, value: NSColor.red, forCharacterRange: range), but since I'm targeting TextKit 2, I have to avoid using NSLayoutManager. Is there a way to achieve this with NSTextLayoutManager or one of the other related classes in TextKit 2?
I'm using this code to get the path of an executable from the audit token provided in NEFilterDataProvider.handleNewFlow(_:), forwarded from the Network Extension to the main app via IPC:
private func securePathFromAuditToken(_ auditToken: Data) throws -> String? {
let secFlags = SecCSFlags()
var secCode: SecCode?
var status = SecCodeCopyGuestWithAttributes(nil, [kSecGuestAttributeAudit: auditToken] as CFDictionary, secFlags, &secCode)
guard let secCode = secCode else {
throw SecError(status)
}
var secStaticCode: SecStaticCode?
status = SecCodeCopyStaticCode(secCode, secFlags, &secStaticCode)
guard let secStaticCode = secStaticCode else {
throw SecError(status)
}
var url: CFURL?
status = SecCodeCopyPath(secStaticCode, secFlags, &url)
guard let url = url as URL? else {
throw NSError(domain: NSOSStatusErrorDomain, code: Int(status))
}
return nil
}
But it seems that some processes like trustd, rapportd, nsurlsessiond and timed have a non-nil path. For these executables I have to resort to this code, which I have read is not as secure:
private func insecurePathFromAuditToken(_ auditToken: Data) throws -> String? {
if auditToken.count == MemoryLayout<audit_token_t>.size {
let pid = auditToken.withUnsafeBytes { buffer in
audit_token_to_pid(buffer.baseAddress!.assumingMemoryBound(to: audit_token_t.self).pointee)
}
let pathbuf = UnsafeMutablePointer<Int8>.allocate(capacity: Int(PROC_PIDPATHINFO_SIZE))
defer {
pathbuf.deallocate()
}
let ret = proc_pidpath(pid, pathbuf, UInt32(PROC_PIDPATHINFO_SIZE))
if ret <= 0 {
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno))
}
return String(cString: pathbuf)
}
return nil
}
This seems to happen with both NEFilterFlow.sourceAppAuditToken and sourceProcessAuditToken. Is this expected? Can it really be that some executables shipped with macOS are not signed?
According to the App Store Connect API documentation we can get the Default App Clip Experience for an App Store Version, and since on the App Store Connect website we have a single App Clip section for an iOS App, it seems that an App Store Version can have 0 or 1 Default App Clip Experience.
But there is no direct way of getting the Advanced App Clip Experiences. The only way I can see is by getting the App Clip object first for the App, then listing all Default and Advanced App Clip Experiences for that App Clip.
This makes me wonder: are Advanced App Clip Experiences not directly linkes to an App Store Version like the Default App Clip Experience? Does the list of Default App Clip Experiences returned from an App Clip object always contain a single object, or can it be more than one (perhaps older versions linked to old App Store Versions)? What is the relationship between App Store Version, App Clip Default Experiences and App Clip Advanced Experiences?
I have a document-based app which displays a view controller with a navigation bar (i.e. it's inside a navigation controller) which is also the detail view controller of a split view controller. I'm using this sample code to just show a back button in the navigation bar of the document view controller:
class DocumentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
splitViewController!.presentsWithGesture = false
navigationItem.backAction = UIAction(handler: { _ in
})
}
}
In a regular width, this works as expected: only the back button is displayed. In a compact width such as a portrait iPhone, the split view seems to display the navigation bar button to show the master view controller (the one with the icon to the right of the back button, labeled “Root View Controller").
According to the documentation of presentsWithGesture:
When this property is false, the split view controller doesn’t install a gesture recognizer for changing the display mode. The split view controller also doesn’t display a button to change the display mode.
Is this a bug, or an error in the documentation, or am I doing something wrong?
By following the documentation, in Info.plist I have added UIApplicationSupportsPrintCommand = true, but when tapping the navigation item's title and selecting Print, printContent(_:) is never called. On the other hand, when selecting Move, move(_:) is called as expected. What's the problem?
The issue can be reproduced by using the code below in a newly created Xcode project with the App template.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "asdf"
navigationItem.documentProperties = UIDocumentProperties(url: URL(fileURLWithPath: "/asdf"))
navigationItem.titleMenuProvider = { suggestions in
return UIMenu(children: suggestions)
}
}
override func move(_ sender: Any?) {
print("move")
}
override func printContent(_ sender: Any?) {
print("printContent")
}
}
In my UI test I'm trying to force the app's user interface style to be light or dark. On macOS, when the system appearance is light, I can force the app to be dark with this code:
var app = XCUIApplication()
app.launchArguments += ["-AppleInterfaceStyle", "Dark"]
app.launch()
Sadly, this doesn't work with a iOS target, and UIScreen.main.traitCollection.userInterfaceStyle is read-only. Is this not possible?
I would like to simulate pressing an arrow key on the hardware keyboard attached to an iPad. In a UI test for a macOS target I can do this:
XCUIElement.typeKey(.rightArrow, modifierFlags: [.option, .command])
but this won't compile for a iOS target supporting iPhone and iPad. Is there an alternative?
What I would like to achieve in the end is moving the text cursor at the beginning of a particular sentence by pressing Option-Command-Arrow left a certain number of times, but if someone knows a better way, I'd be happy to hear it.
The following code should produce 6 spinning progress indicators of varying sizes: 3 indeterminate and 3 determinate ones. The first two of the 3 determinate ones are either entirely or partially cut off, which doesn't happen with the indeterminate ones. What's the problem?
var progress = NSProgressIndicator(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
progress.style = .spinning
view.addSubview(progress)
progress = NSProgressIndicator(frame: CGRect(x: 50, y: 0, width: 24, height: 24))
progress.style = .spinning
view.addSubview(progress)
progress = NSProgressIndicator(frame: CGRect(x: 100, y: 0, width: 32, height: 32))
progress.style = .spinning
view.addSubview(progress)
progress = NSProgressIndicator(frame: CGRect(x: 150, y: 0, width: 16, height: 16))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)
progress = NSProgressIndicator(frame: CGRect(x: 200, y: 0, width: 24, height: 24))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)
progress = NSProgressIndicator(frame: CGRect(x: 250, y: 0, width: 32, height: 32))
progress.style = .spinning
progress.isIndeterminate = false
progress.doubleValue = 50
progress.maxValue = 100
view.addSubview(progress)
When I open an iOS app in the App Store Connect website and disclose the Apple Watch section, it reads Apple Watch Ultra, Series 8, 6, 3, but the documentation for the API lists different versions:
APP_WATCH_ULTRA
APP_WATCH_SERIES_7
APP_WATCH_SERIES_4
APP_WATCH_SERIES_3
So the Watch Series don't seem to match.
There is a similar issue with iPad Pro. The website reads iPad Pro (6th Gen) 12.9" Display and iPad Pro (2nd Gen) 12.9" Display, but the API reads
APP_IPAD_PRO_3GEN_129
APP_IPAD_PRO_129
So again the Gen values don't seem to match.
How should I interpret these values?