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:
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?