Post

Replies

Boosts

Views

Activity

CD4CK: Can't find Default configuration in M.O.M.
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]
2
0
1.5k
Aug ’19
Can't modify System Power Management preferences
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?
0
0
803
Mar ’20
Querying Class & Command Descs from NSScriptSuiteRegistry
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.
21
0
4.1k
Mar ’20
AppUITests bundle ID suffixed with .xctrunner!?
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.
2
1
2.4k
Mar ’20
AECreateAppleEvent from Swift issues.
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)
4
0
1.3k
Apr ’20
Forum area of legal questions?
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?
1
0
645
Apr ’20
Export using Drag & Drop to Finder?
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?
5
0
1.2k
Apr ’20
XCTest overriding defaultMetrics not working for me.
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.
0
0
703
Apr ’20
Importing XCTest into a framework target
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.
2
0
1.3k
Apr ’20
XPC Mach Services from App Bundle?
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.
7
0
2.3k
May ’20
Working with init that takes a 32 element tuple?
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?
3
0
831
May ’20
Can't deploy framework to /Library/Frameworks
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.
2
0
1.6k
May ’20
Privileged Mach Service only replies when attached to debug
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.
3
0
953
May ’20
Background processing options for Mac App Store apps?
I'm busy designing my app's functionality and really would like to provide some features that rely on background processing after the user has logged in. A Login Item seems ideal for this use case. I appreciate the lengths Apple go to, to communicate the complex technologies involved in app development, including the planning of macOS apps. I haven't found any information in the planning and design (admittedly under HIGs) documentation on whether it's possible to provide some background processing element along with an app destined for the Mac App Store. Perhaps it's not mentioned for a reason? However, it would be really useful to background processing dealt with up-front, especially under planning, because it has a huge impact on how one moves forward with product design. Especially when you're an indy developer with limited time and resources. I can't, for the life of me, find where I previously read that daemons and agents weren't allowed to be shipped with a Mac App Store app, because of the Sandbox requirements. It was probably a reply by Eskimo somewhere in the forums. Does the same apply to Login Items? The bulk of the Login Item documentation is in the documentation archive, most of which was written before the existence of the app stores, so I couldn't find any answers there. I previously believed that an app destined for the Mac App Store could only include a single binary, that of the main app itself. Although I've seen the recent article on including a command line utility binary in the distribution too. Also, if my understanding of code signing is correct, apps distributed via an app store are signed by Apple, and thus can't communicate via XPC with a binary signed and distributed via a Developer ID. Or is there some workaround there that might get me closer to my goal?
5
0
668
Apr ’24
Anti-Piracy measures for Mac App Store apps?
As an indy developer, it's prohibitive to start developing backend receipt validation services. Is there anything else in Apple's technologies that we can use to verify whether the person who is using my app, has paid for it? The first thing I thought of when Apple rolled out Sign in with Apple ID, was hopefully, it would include some API that would allow me to ask a simply question: did this Apple ID pay for my app? As an indy developer, this is the one feature that would keep my paid app on the Mac App Store. Anyone have any good suggestions for solving this as an indy developer?
7
0
1k
Apr ’24