40

I recently updated to macOS Catalina so I could update some of my apps with Mac support using Catalyst. Whenever I run the app and it tries to access the CloudKit data (I use CloudKit to sync Core Data, Data if an iCloud Account is available), it then crashes with the following error. [User Defaults] Couldn't write values for keys ( ApplicationAccessibilityEnabled ) in CFPrefsPlistSource<0x600002c07700> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

I have tried changing Permissions and Access in App SandBox settings in my Signing and Capabilities, to read/write. I have also tried changing incoming and outgoing connections to on.

I am not exactly sure what code I should show so here is the area is crashes in.

if isICloudContainerAvailable() {
            print("iCloud Available")
            let container = NSPersistentCloudKitContainer(name: "Shopping_App")
            
            container.loadPersistentStores(completionHandler: {
                (storeDescription, error) in
                if let error = error as NSError? {
                    fatalError("Unresolved error \(error), \(error.userInfo)")
                }
            })

            return container
}

I except the app to create/get the CoreData data and if available (which is in this case) to connect to the CloudKit synced data. But it crashes right now before it even brings up any views which leads me to think that it is crashing in the AppDeleget somewhere.

Update Oct. 14 -- I found that if I force Jump Over the Breakpoint where the app crashes, I can continue into the app and it works fine. Which leads me to think that the error is really in the AppDeleget especially saying that the UI does not appear until after I jump over the breakpoint it sets at the crash.

Update Nov. 4 -- So this problem gets even stranger. I forgot I was using a beta version of Xcode, so ok, it could have just been that after I realized that last week. I tried running the app through the public version and the app never stopped for a breakpoint but instead completely crashes with Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). This error is just really odd. Would this be an error that I should report to Apple? I thought about doing that but I decided not to because it seemed to me like something I could have been doing, but now rethinking whether I should or not. I wish I could find the solution to this problem because I would like to release the macOS version to the public, but have not had any luck finding a solution.

Update Nov. 8 -- In Xcode 11.2.1 GM seed the problem still persists. I have yet to find the exact reason this problem occurs but will continue to try. I have also been unable to reproduce the error written in the update on Nov. 4, on any Xcode version. I have not found anything else but wanted to update this with information about the GM seed and if this still happens.

Update Nov. 13 -- I decided to just go ahead and upload the app to Apple for approval since building the app and running it independently from Xcode worked just fine. Apple approved the app without any complaints of this issue. This just seems to be an Xcode issue. I will continue to update this however and if/when I find a solution I will post the solution to this problem but have not found anything more to workaround or solve this problem.

Update Nov. 20 -- On Xcode 11.3 Beta Build 11C24b, the problem still occurs. Nothing else has changed and I have not found anything else to solve this problem. I will continue to keep this updated but have not found anything else yet.

Update Dec. 11 -- On Xcode 11.3 Public 11C29 the problem still continues. However, now it is not consistent and sometimes I have to go over the breakpoint twice instead of just once for the application to continue launching. It still does not occur though if ran independently from Xcode.

Update Jan. 2, 2020 -- Still occurs but now verified that it occurs on a real iOS 13 device. No other solutions or stepovers found though. I will continue to update this post however with any other information.

Update Feb. 17, 2020 -- Not much of an update but still occurring on Xcode 11.4 Beta (11N111s). Will continue updating this post however not much has changed. (Fixed some misstakes on this post as well)

Update March 10, 2020 -- I did not realize that Xcode beta 11N132i was released but after testing it still occurs. However, though it may still be occurring, it is at least less consistent. Now instead of it happening and doing this every time, it appears to be somewhat random.

Update April 18, 2020 -- Sorry for not updating this post, I have been unable to program until now. I still have not figured out this issue but it seems that now it is not really happening. It still happens just rarely now. This also is on Xcode 11.4.1 (11E503a), and I am not sure why still. I will continue to try and update this post. Thank you. If you have any suggestions to try to find the cause, I am open to hearing them.

Update May 14, 2020 -- Xcode 11.5 Beta 2 (11N605f) This problem still occurs randomly, but now it seems to not always include the error yet still points to that portion of code. Thank you for your support of this post, and I will continue updating it as I find more about this problem.

Update Jun 5, 2020 -- I am sorry for not updating this any sooner, I completely forgot when I had updated Xcode. On Xcode 11.5 this problem still persists like it has been. I have also updated to Catalina 10.15.5 and have seen little to no changes. However, like the comments have said, Catalina 10.15.4 did help this has I heard, but 10.15.5 seemed to not change anything, which is strange.

Update Jun 27, 2020, and July 22, 2020, and Aug 10, 2020 -- I have updated my project to now support Xcode 12 and it appears to still have the same issue. Nothing has really changed and the log is the exact same. I appeaciate everyone willing to contiune in helpin fix this issue as well. This is also the same on Xcode 12 Beta 2. The excat same for betas 3 and 4.

Update Sep 28, 2020 -- This is still an issue on the GM and Public versions of Xcode 12. I have not updated to Xcode 12.0.1 because I am waiting for macOS Big Sur, but at this point, I doubt that would solve it. I really do not have any updates, other then it still is occurring and I cannot find the issue.

Update Nov 3, 2020 -- This still appears to be an issue on Xcode 12.1.1 Release Candidate. Sorry for not updating this for so long, I was holding out updating Xcode as I previously stated, but I decided to go ahead and update. However, updating to the Release Candidate has not changed anything, or not at least that I can notice. One change I did notice; however, was that it seemed to show this issue sooner, but that could just be that it compiles it quicker. To summarize, no major changes to this problem and nothing has really changed with it in a while.

UPDATE Nov 16, 2020

I have since updated to macOS Big Sur 11.0.1 and updated Xcode to 12.3 beta. The problem still seems to occur after having to change a few random things to get it working on Big Sur. However, most everything I changed I think is unrelated because it was mostly related to the UI elements. This may just be Big Sur but it compiles much faster, and the error now shows much quicker; however it still is the same error.

117MasterChief96
  • 548
  • 1
  • 5
  • 16
  • 3
    This seems to be an Xcode problem. I thought I should try building the application and exporting it as an app and running it, and believe it or not, it worked just fine without any problem. So this leads me to just think this is an Xcode problem not a problem with my app. – 117MasterChief96 Oct 15 '19 at 15:19
  • Hey MasterChief,we working on a project with Catalyst and cloudkit, Silent notification working fine both iPhone and iPad but not working in Mac App(Catalyst) => (didReceiveRemoteNotification) didn't get any notification on Mac App, Did you have any idea ? – Manikandan D Jan 14 '20 at 17:12
  • My apologies if I miss understand you but this might be a bit off-topic from this question so you might want to open your own question. But I am not completely sure. Make sure you added the capabilities and turned on incoming and outgoing signals. Hopefully that helped if not look into opening a new question possible with more detail and I can see if I can help. Thank you – 117MasterChief96 Jan 15 '20 at 18:33
  • https://stackoverflow.com/questions/59778113/bug-check-cloudkit-maccatalyst-didreceiveremotenotification – Manikandan D Jan 17 '20 at 09:00
  • 3
    Really appreciate your updates here In behalf of “I’m having the same issue” people like me... – Jakub May 15 '20 at 18:33
  • You're welcome. Glad I am not the only one having this problem. – 117MasterChief96 May 17 '20 at 12:20
  • Same problem here, even though my app doesn't crash I receive some logs on the console that I rather see solved, I'm afraid that some of them might break my app sooner or later – Pedro Cavaleiro Jul 02 '20 at 21:10
  • Still an issue with Xcode 12 release version. – RickJansen Sep 28 '20 at 08:55
  • @RickJansen yes it is. I have tried to keep this updated with that, but nothing has really changed with it being an issue. – 117MasterChief96 Sep 28 '20 at 14:47
  • I filed a bugr.. feedbackreport. Also, there are problems with accessing the bundle for images in embedded HTML in in-app web pages. – RickJansen Sep 28 '20 at 16:53
  • I have had issues, as well, with bundle images, but I do not think with embedded HTML. – 117MasterChief96 Sep 28 '20 at 17:37
  • The HTML works, but the images in the HTML not. Odd is that the sandbox log errormessages appear even before "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions", so before my code gets control. I don't understand that really. – RickJansen Sep 28 '20 at 17:48

3 Answers3

2

MasterChief96, you are not alone. Here is my setup:

MacOS 10.15.3 Xcode 11.4.1

I create a brand new SwiftUI "Hello World" project, enable Mac as a target device, a.k.a. Catalyst.

I set the iOS deployment target to 13.2 (otherwise I get a MacOS runtime error saying I need Catalina 10.15.4)

Set the scheme to "My Mac", compile and run and get:

[User Defaults] Couldn't write values for keys
    ApplicationAccessibilityEnabled
    AccessibilityEnabled
    FullKeyboardAccessFocusRingEnabled
setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

Since it refers to the sandbox, I change the "Signing and Capabilities" setting for App Sandbox to include Read/Write for User Selected and Downloads File Access.

I quite Xcode, delete the project's Derived Data, open the project and run. The error messages persist when running on MacOS. (I do not see the messages when running on iOS.)

Just guessing here, but this appears to be yet another bug in the Catalyst environment? Maybe this bug is fixed in Catalina 10.15.4 but that update was such a disaster for me I had to back port to 10.15.3.

WholeCheese
  • 437
  • 3
  • 14
  • 1
    I tried the same File Access Type settings, but the actual error is ```Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access``` And I don't see a "User-Preference Write setting. I see User Selected File – Michael Rowe May 23 '20 at 18:41
  • (This is in reply to WholeCheese) That defiantly seems to be the case, but like you said it is not the best idea to update to Catalina 10.15.4. The strange part is that I updated to Catalina 10.15.5 and have yet to find any unstable problems, but by project had no change like you said in Catalina 10.15.4 did and like I heard from others. – 117MasterChief96 Jun 05 '20 at 19:50
0

For me, I was getting this exact error message but the crash was happening due to the next error message where it was referring to missing CFBundleName in the Info.plist for my Mac Catalyst app.

The snippet of stack trace:

(Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
2020-06-27 11:01:52.403837-0700 Manga Relay D[17329:517025] [General] An uncaught exception was raised
2020-06-27 11:01:52.403908-0700 Manga Relay D[17329:517025] [General] *** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: title)
2020-06-27 11:01:52.404006-0700 Manga Relay D[17329:517025] [General] (
    0   CoreFoundation                      0x00007fff2eb82be7 __exceptionPreprocess + 250
    1   libobjc.A.dylib                     0x00007fff6795a5bf objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff2ec3160e -[__NSCFString characterAtIndex:].cold.1 + 0
    3   CoreFoundation                      0x00007fff2ec3c17c -[__NSDictionaryM setObject:forKey:].cold.3 + 0
    4   CoreFoundation                      0x00007fff2eac0329 -[__NSDictionaryM setObject:forKey:] + 976
    5   UIKitCore                           0x00007fff6f5f2c8f -[_UIMenuBarItem properties] + 99
    6   UIKitMacHelper                      0x00007fff5fd6272a UINSNSMenuItemFromUINSMenuItem + 90
    ...

Once I specified a name in the "Bundle name"(aka CFBundleName), the crash went away but I still do get the error message about setting preferences outside an application's container.

Update with more details: The following screenshot of my Info.plist is defining the CFBundleName as my user-defined variable like $(MangaRelayBundleDisplayName) and I found out I never defined this anywhere, so it was nil which was causing the crash. When I entered the value such as "My App", the crash went away. Now, this solution has nothing to do with the original question, and basically I was mislead by the "sandbox access" warning, but I figured there could be other people who are being mislead by the warning.

Info.plist screenshot

I am on macOS 10.5.5 and Xcode 11.5.

Genki
  • 3,055
  • 2
  • 29
  • 42
  • 1
    If you are able to, could you please provide an example of what you mean by adding the CGBundleName? – 117MasterChief96 Jun 28 '20 at 01:27
  • Yeah, I just updated with a screenshot and little more explanation. @117MasterChief96 – Genki Jun 28 '20 at 01:50
  • 1
    Thank you. I actually already had this but thank you for the suggestion. Hopefully as you said though `but I figured there could be other people who are being mislead by the warning`. Hopefully your sugggestion will be able to help other people confused by this warning. – 117MasterChief96 Jun 29 '20 at 11:35
-1

I had the same problem. Solved by deleting the "All runtime Issue" breakpoint.

After tests,

  • Thread Satanizer (Runtime Issue) works fine
  • Undefined Behavior (Runtime Issue) works fine
  • Main Thread Checker (Runtime Issue) works fine
  • System Frameworks (Runtime Issue) BREAK