Posts

Post not yet marked as solved
2 Replies
1.2k Views
There are a few things about how Core Data 4 Cloud Kit initializes that I'm stuggling to understand. I've spent most of the day finally getting a schema initialized on the server, and learnt a few things along the way.Firstly, even though I have a Default configuration in my managed object model, and it has been there from day one with the option "Used with CloudKit" checked for true, if I create an `NSPersistentStoreDescription` and set the configuration property to "Default", when I try to load the stores, it will fail, saying "Unable to find a configuration named 'Default' in the specified managed object model.". If I inpsect the debug description for my ManagedObjectModel instance, it does indeed not have any reference to the string "Default" in it (I'm not sure if debugDescription is actually printing out the configuration names however). Why does this fail? I can only get my store loaded and the schema initialized if I remove the code that sets the configuration name to "Default".The next thing that tripped me up was the NSPersistentCloudKitContainerOptions property on the store description. Considering that the only property on that class is now gone, so you no longer need to perform `options.shouldInitializeSchema = true`, I incorrectly assumed that I'd no longer need to even create and set a NSPersistentCloudKitContainerOptions instance on my store description, because all it really holds is the containerIdentifier. Why would I need to specify a container identifier if the system is going to fetch the first iCloud Container Identifier out of the entitlements file and associate it with the Default configuration which I'd (clearly incorrectly) assumed would be automatically associated with CloudKit and my "Default" entitlement container identifier.Below is the code I was using. It's mild playground refactor of my real code, but it's quite straightforward.// Instantiate the Managed Object Model let modelName = "CloudModel" let url = Bundle.main.url(forResource: modelName, withExtension: "momd") let mom: NSManagedObjectModel = NSManagedObjectModel(contentsOf: url!)! // Define the Cloud Store Description let storeURL = URL(fileURLWithPath: "Cloud.sqlite", isDirectory: false, relativeTo: NSPersistentContainer.defaultDirectoryURL()) let cloudStoreDescription = NSPersistentStoreDescription(url: storeURL) cloudStoreDescription.shouldAddStoreAsynchronously = true cloudStoreDescription.configuration = "Default" // this will cause loading to fail with an "Unable to find // a configuration named 'Default' in the specified managed object model." error // Add a container options instance to the description, because without it, loading will fail with // "Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit" var cloudKitOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "com.example.container.identifier") cloudStoreDescription.cloudKitContainerOptions = cloudKitOptions // Create the Container for the Cloud Store let container: NSPersistentCloudKitContainer = NSPersistentCloudKitContainer(name: modelName, managedObjectModel: mom) container.persistentStoreDescriptions = [cloudStoreDescription]
Posted Last updated
.
Post not yet marked as solved
2 Replies
955 Views
Is it by design that we are not able to succesfully load the XCTest framework into our own framework targets?I can add it to my framework target's list of linked frameworks, and import it into a source code file, and even build my project successfully, but after it's built, Xcode will display a red error inline at the import site with the message "Failed to load module 'XCTest'". My framework target even builds if I refer to an XCTest type in my code.I got to this point because I was trying to use XCTPerformanceMetric(rawValue: ""). The call works in my test target, but in a framework target it tells me the rawValue version of the constructor does not exist. Of course, as i type this, I'm still receiving the load module error, but now the compiler doesn't complain if I use the rawValue constructor. Can anyone enlighten me? Thanks.
Posted Last updated
.
Post not yet marked as solved
2 Replies
2k Views
I've started developing my first macOS app and chose "Automatically manage signing" because life's too short.Since I added iCloud capabilties to my macOS app, the AppUITests target won't build because it's saying the AppUITests requires a provisioning profile with the bundle IS suffixed with "UITests". (Don't recall ever having this issue with iOS.)So I go through the process in my online account to create a provisioning profile, (eventually with the correct iCloud entitlements etc) and install it and update my UITests target to point to it.Now it's telling me it can't build the UITests target because the bundle ID in the provisioning profile doesn't end in "UITests.xctrunner" !Is this normal? Because it seems quite convoluted, and do I really have to go through the process again and create profile with bundle ID that ends in "UITests.xctrunner". I don't know where the "xctrunner" suffix came from, but it's certainly not present in my build settings.Any help would be great! Thanks.
Posted Last updated
.
Post not yet marked as solved
3 Replies
706 Views
I've been following the Even Better Authorization Sample to a degree, and I've successfully deployed a privileged helper service that is definitely launched by my app on-demand. For now, it's launched by an XPC service (I need the process isolation) that returns the privileged helpers service endpoint.If I then try to call any of the APIs on the privileged remote service from within my app, they simply disappear into the ether, never to be returned or heard from again. So my app is left in this hung state.I've made some progress after I discovered that you can attach to the PID to debug it as root in Xcode. When I did that, it seemed like the debugger took me through the process's main() function and the init of the service itself. Which I thought was odd considering the process was already running. After that, I launched my app in Xcode to debug it, and calls to the privileged process worked perfectly and returned exactly what I was expecting. Plus all the os.log streams showed exactly what they should. Previously nothing was output via the logging system.So I guess my questions are:1) Why does the debugger take me through the process's main() and the init of the service when I attach to the already running privileged process? Does that indicate that something is not right, or not happening as it should while its running on its own?2) I'm guessing its a permissions thing as trying to attach as myself to debug I get an SIP message: "Process attach denied, possibly because System Integrity Protection is enabled and process does not allow attaching." I assumed (I know, stupid idea) that because I'd specified that my XPC process had permission to add and remove this helper tool, that it would also be allowed to attach to it. I'm guessing not. Which leaves me wondering, how do I attach to this process with SIP in the way? 3) How can I possibly debug why the privileged process won't process requests while Xcode is not attached to it for debugging?Any advice or help would be greatly appreciated. Thanks.
Posted Last updated
.
Post marked as solved
2 Replies
1.2k Views
I'm trying to deploy a framework to /Library/Frameworks but I'm not sure if I'm dealing with a permissions issue or build configuration issue, or something else.In the framework target's Deployment section I've set:Deployment Location: YesDSTROOT: /INSTALL_PATH: /Library/FrameworksSkip Install: NoI get the following error when building for running:SymLink /Library/Frameworks/MyKit.framework/Versions/Current A (in target 'MyKit' from project 'MyKit') cd /Users/rayascott/Developer/bitbucket/MyApp/MyAppSpace/Projects/MyKit /bin/ln -sfh A /Library/Frameworks/MyKit.framework/Versions/Currenterror: unable to create symlink at '/Library/Frameworks/MyKit.framework/Versions/Current' (in target 'MyKit' from project 'MyKit')Nothing is deployed to /Library/Frameworks/.I've given Xcode full disk access, but I'm guess that's not enough for it to access system folders. Am I better off with a zsh script and sudo from the command line to deploy this? I do really need to place it there, as I have a priviledged helper tool that needs to access this framework.On a side note: how would a user of my app be able to deploy this framework to /Library/Frameworks if they aren't an Administrator? Would I then have to deploy to ~/Library/Frameworks? But I see that's discouraged. How does everyone else get this working in for a deployed release build? Thanks.
Posted Last updated
.
Post marked as solved
3 Replies
611 Views
I'm busy working with the Authorization Services APIs and came across an initializer for the type AuthorizationExternalForm that takes a 32 element tuple of UInt8s.init(bytes: (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8))Ref here: https://developer.apple.com/documentation/security/authorizationexternalform/1396798-initIs there a shortcut to converting the contents of Data to that without explicitly referencing each element in a byte array?
Posted Last updated
.
Post not yet marked as solved
7 Replies
1.8k Views
Is it possible to include an XPC Service target in my app bundle that is designed to run as a mach service with the launchd username set to root? I know, it sounds like a terrible idea, but I've done some reading, and I'm learning about Authorisation Services and the EvenBetterAuthorizationSample project.The idea is to have a privledged helper be accessible from other processes such as a command line tool or menubar app. What are the other settings besides Application for the XPC ServiceType in the Info.plist. The ServiceType key isn't even documented in the Daemons and Services Programming Guide. The other thing I'm hoping to acheive is to lanuch the same XPC service code as two seperate launchd services. One as root and one as the logged-in user.
Posted Last updated
.
Post not yet marked as solved
0 Replies
495 Views
I'm trying to get a handle on XCTest performance measurement, but they don't seem to work the way I understand them (which is very possibly incorrect).There are:defaultMetrics: [XCTMetric]- "Subclasses of XCTestCase can override this property to change the default metrics."- which includes: XCTClockMetric, XCTCPUMetric, XCTMemoryMetric, et al.and:defaultPerformanceMetrics: [XCTPerformanceMetric] - "Subclasses of XCTestCase can override this method to change the behavior of measure(_:)."- which includes the sole: wallClockTime: XCTPerformanceMetricIf I override: override class var defaultMetrics: [XCTMetric] { return [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()] }and call:self.measure(work)All I see in the report is Duration and Time.Yet if I pass an array of metrics in,self.measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()], block: work)it works and displays CPU Cycles and Memory Physical etc.Shouldn't the measure() method use the defaults I've specified? Also, if I've overridden defaultPerformaceMetrics(), those metrics are only displayed if I don't pass XCTMetrics to measure(metrics:). Ultimately, what I want is a report that displays the XCTMetrics I specify as well as the XCTPerformanceMetrics. I know there are other perf metrics beyond just wallClockTime.
Posted Last updated
.
Post not yet marked as solved
5 Replies
907 Views
I have this idea for my document-based app that I'm not sure is possible, so I'm hoping someone with experience can shed some light on this for me. Imagine I've got an NSDocument but it's actually represented as a package, a folder on disk. Let's call this folder-based document a Project document. Inside the Project document's package folder I've got, for all intents and purposes, BLOBs. These BLOBs are represented in the app's GUI as dragable UI elements. Is it possible to code my app so that, when a user drags and drops one of these UI elements representing a BLOB into the Finder, a new Project document is created and the BLOB is placed inside this newly created package? The BLOBs can't exist outside of a Project document package, so if I want to export a BLOB it needs to be wrapped inside a Project document.The BLOBs aren't of a known standard type such as an image file format or video file format. They are of a custom format that's only meaningful within the context of my app. Does anyone know if this is possible?
Posted Last updated
.
Post not yet marked as solved
1 Replies
493 Views
Where do we post questions of a legal nature? I know these are more technical forums, but as developer's we can still have quite a lot of questions regarding what is and isn't permissable. My interest stems from a question I have regarding the use of (AppKit's) NSRunningApplication's icon property that returns an image of that third party app's icon. Does this mean we are allowed to display these app icons in our app if you can justify its usage is valid and beneficial to the user of your app?
Posted Last updated
.
Post marked as solved
4 Replies
955 Views
I'm tyring to send an AppleEvent using the C API's from Swift. I know I can use the Foundation types, but I want to learn about Swift / C interop at the same time. If someone could help me understand why this AppleEvent isn't sending and I'm getting a -1701 (No AEDesc Found) error, I'd be extremely grateful. The problem is a) I'm new to C interop and b) I don't know which AEDesc the error is actually referring too and c) if I'm using the C API correctly. I'm trying to open TextEdit. let textEditID = "com.apple.TextEdit" let textEditIDC = textEditID.cString(using: .utf8)! let textEditPtr : UnsafeMutablePointer<[CChar]> = UnsafeMutablePointer<[CChar]>.allocate(capacity: textEditIDC.count) textEditPtr.initialize(to: textEditIDC) let ds : AEDataStorage = AEDataStorage(OpaquePointer(textEditPtr)) let address : AEAddressDesc = AEAddressDesc(descriptorType: typeApplicationURL, dataHandle: ds) let addrPtr = UnsafeMutablePointer<AEAddressDesc>.allocate(capacity: 1) addrPtr.initialize(to: address) let eventPtr : UnsafeMutablePointer<AppleEvent>? = UnsafeMutablePointer<AppleEvent>.allocate(capacity: 1) let replyPtr : UnsafeMutablePointer<AppleEvent>? = UnsafeMutablePointer<AppleEvent>.allocate(capacity: 1) var error = AECreateAppleEvent(kCoreEventClass, kAEOpenApplication, addrPtr, Int16(kAutoGenerateReturnID), AETransactionID(kAnyTransactionID), eventPtr) os_log(.debug, log: .default, "AECreateAppleEvent: %d", error) var ae = eventPtr?.pointee let addrDescPtr : UnsafeMutablePointer<AEDesc> = UnsafeMutablePointer<AEDesc>.allocate(capacity: 1) error = AEGetAttributeDesc(eventPtr, keyAddressAttr, typeApplicationBundleID, addrDescPtr) os_log(.debug, log: .default, "AEGetAttributeDesc: %d", error) let status = AESendMessage(eventPtr, replyPtr, Int32(kAEWaitReply), 900) os_log(.debug, log: .default, "send event rc: %d", status)
Posted Last updated
.
Post not yet marked as solved
21 Replies
3.1k Views
Hi!I want to get access to the NSScriptClassDescription & NSScriptCommandDescription objects for a running application via the NSScriptSuiteRegistry object but I'm not having much luck.I was hoping that all running applications that have a sdef file would be listed when calling the var suiteNames: [String]function, but this doesn't return any suite names for running apps that have sdef files. It returns names like NSCoreSuite, NSTextSuite, ASKDocumentSuite.I then thought perhaps the suites aren't loaded until the app responds to an Apple Event so I fired off a quick NSScriptObject instance targeting the app I'm wanting to see the suite defs for, but that had no effect on suite names ruturned from NSScriptSuiteRegistry.Is it even possible to inspect the AppleScript definition for a 3rd party or Apple app with NSScriptSuiteRegistry? I really don't want to have to import an sdef into Core Data and build it myself, if I can simply query the system at run time.
Posted Last updated
.
Post not yet marked as solved
0 Replies
669 Views
I'm looking at the open source code for the pmset command and attempting to modify the DisableSleep key in macOS's power management settings.It seems to come down to running the following line of code where msdict contains a boolean value for "SleepDisabled":let PMEyeIOCFPrefsPath = "com.apple.PowerManagement" let PMEIOSystemPowerSettingsKey = "SystemPowerSettings" CFPreferencesSetValue(PMEIOSystemPowerSettingsKey as CFString, msdict as CFDictionary, PMEyeIOCFPrefsPath as CFString, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)You need to be root to do this, and this code won't run from the pmset command line tool unless run as root. When I run the above from a menubar app I'm writing, I get the following explanation...2020-03-19 16:15:03.527875+0000 Open Eye[16320:301001] [User Defaults] attempt to set { SleepDisabled = 1; "Update DarkWakeBG Setting" = 1;} for key in SystemPowerSettings in read-only (due to a previously logged write error) preferences domain CFPrefsPlistSource<0x600002c14e80> (Domain: com.apple.PowerManagement, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: No)Ultimately I'm trying to run a few pmset commands from a menubar app so I don't have to continually lookup keys and open the terminal just to keep my system awake. So how can I get this code to run with or without a popup to authenticate as root?
Posted Last updated
.
Post not yet marked as solved
0 Replies
464 Views
I was hoping to write some automation around the simctl utility and I'm wondering if anyone knows how to deteremine which app has been launched most recently on a simulator?I've tried inspecting the modification timestamps on files and directories with varying degrees of success. Maybe there's a SQLite store or plist for the Springboard that I could query? Any advice would be greatly welcomed.
Posted Last updated
.
Post marked as solved
5 Replies
1.8k Views
I just opened up a Swift Package in Xcode that I'm developing and the majority of the Swift files are disabled. I click on them and I get a system noise but that is all. In the Inspector pane, they aren't even recognised as Swift source. If I select Swift source from the Type drop down list, I notice that the text encoding is set to No Explicit Encoding. If I select UTF-8 it prompts me to confirm conversion, so I backed out. The reason I did, is that from the command line, if I use the `file -I` command it tells me that the files are indeed UTF-8. Also, for a project that had schemes, it now has none. I know the default is to create a Swift Package without a scheme, but I prefer what I'm familiar with.I recloned the repo from bitbucket, but the results were exactly that same. So now I'm not sure where the problem is. Did Bitbucket corrupt my files? Are both Xcode 11.1 and Xcode 11.2 Beta 2 to blame? I doubt it, but the files are clearly Swift UTF-8. Any ideas on how I can get Xcode to recognise my Swift source and magically restore my schemes? :-(
Posted Last updated
.