Using MAUI SecureStorage on a MacCatalyst app

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?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật