2

Developing a MAUI app on a Mac mini (M1) with Rider 2024.1.2 targeting MacCatalyst.

TL;DR: I'm trying to get a simple app working that sets and gets a value from SecureStorage in a MAUI app targeting MacCatalyst, but I get various errors and I don't know where to go from here.

Full details

I've been going around in circles on this for a few days now. I'm learning MAUI and doing a tutorial that uses secure storage. It wasn't the focus of the tutorial so when it errored, I worked around it after a while as the documentation and various forum posts I've read assumes a lot of context I don't have as a newbie to MAUI and Apple development. I've since got an Apple Developer account now and I've come back to look at Secure Storage.

Attempt 1:

I've created a simple app that just gets and sets stuff in Secure Storage.

The GetSecureStorage_OnClicked method always gets null because I've not been able to set anything to secure storage.

private async void SetSecureStorage_OnClicked(object? sender, EventArgs e)
{
    try
    {
        var value = NewValue.Text; // An Entry control
        await SecureStorage.SetAsync("MauiSecureStorageExample", value);
        await DisplayAlert("Set Value", $"Set value to {value}", "Okay");
    }
    catch (Exception ex)
    {
        _logger.LogError(ex, "Exception happened.");
    }
}

This fails with the exception:

System.Exception: Error adding record: MissingEntitlement
   at Microsoft.Maui.Storage.KeyChain.SetValueForKey(String value, String key, String service)
   at Microsoft.Maui.Storage.SecureStorageImplementation.SetAsync(String key, String value, SecAccessible accessible)
   at Microsoft.Maui.Storage.SecureStorageImplementation.PlatformSetAsync(String key, String data)
   at Microsoft.Maui.Storage.SecureStorageImplementation.SetAsync(String key, String value)
   at Microsoft.Maui.Storage.SecureStorage.SetAsync(String key, String value)

Attempt 2:

So, I follow some documentation I found, and I add to my Entitlements.plist file, it now looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
    <key>keychain-access-groups</key>
    <array>
        <string>$(AppIdentifierPrefix)com.companyname.mauisecurestorage</string>
    </array>
</dict>
</plist>

And now I've got the following error when trying to launch the application:

The application cannot be opened for an unexpected reason, error=Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x6000035b84b0 {Error Domain=NSPOSIXErrorDomain Code=153 "Unknown error: 153" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}

When I go back to look at the build output, I noticed this warning: 0>Entitlements.plist: Warning : Cannot expand $(AppIdentifierPrefix) in Entitlements.plist without a provisioning profile.

Attempt 3:

After some time going round various docs, this is where I think the Apple Developer account comes in. So, once signed up, I try and create a provisioning profile by following the docs, They're not set out top to bottom so I have to go around and around for a bit.

Eventually, I get everything set up so that I can install the profile on my Mac: Secure Storage Example Provisioning Profile

The docs say I have to download it into Xcode, while it automatically installed into my settings. So I do that too, although the UI doesn't really show me that it's done anything.

I restart Rider, clean the solution and rebuild it to ensure nothing has been left hanging around from a previous attempt... And I get the same warning in the build and error when the app launches.

Attempt 4:

This time, now that I have a profile, I manually update the Entitlements.plist file to replace the $(AppIdentifierPrefix) with the App ID Prefix value displayed on my Apple Developer page.

That gets rid of the warning in the build, but it still fails to run with a similar error as before, the NSUnderlyingError code is different. I was unable to find an explanation for it.:

The application cannot be opened for an unexpected reason, error=Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x600002d603f0 {Error Domain=NSPOSIXErrorDomain Code=153 "Unknown error: 153" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}

At this point I've no idea what to try next, or what I've missed out. Can you help?

5
  • You are testing this on a real device? Commented Jun 10, 2024 at 7:49
  • 1
    It's all running on my Mac. MacCatalyst, as far as I'm aware, does not need a simulator as it targets a Mac and is being developed on a Mac, so it is running on the same machine it is being developed on. Commented Jun 10, 2024 at 8:58
  • I have ever create MacCatalyst app before, however, I have a real MacBook and VM for signing iOS only, if you provide a minimal reproducible example, it will be my kick-start to MacCatalyst and perhaps, I can provide you with a solution or a suggestion Commented Jun 10, 2024 at 10:02
  • 1
    Here you go, I create a Git repo with the solution in it here. It is just the base MAUI template with the main page updated. This link is to the Main Page which is what gets and sets the secure storage item: github.com/colinangusmackay/MauiSecureStorage-StackOverflow/… Commented Jun 10, 2024 at 15:48
  • @ColinMackay, Have a look here github.com/dotnet/maui/issues/8326 , I'm working on it. Commented Jun 12, 2024 at 21:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.