I'd like to try ManagedAppView describe here: https://developer.apple.com/documentation/appdistribution/fetching-and-displaying-managed-apps
// Define a model that obtains a list of managed apps.
@Observable final class PortalViewModel {
enum Content: Identifiable {
case managedApp(ManagedApp), developerContent(title: String, action: (ManagedContentOfferState) -> Void)
var id: String {
switch self {
case let .managedApp(app):
return app.id
case let .developerContent(title, _):
return title
}
}
}
var contents: [Content] = []
func getApps() async {
do {
for try await result in ManagedAppLibrary.currentDistributor.availableApps {
contents = try result.get().map(Content.managedApp)
}
} catch {
// Handle errors here.
print("ERROR==>\(error)")
}
}
}
struct PortalView: View {
private var viewModel = PortalViewModel()
var body: some View {
List(viewModel.contents) { content in
switch content {
case let .managedApp(managedApp):
ManagedAppView(app: managedApp)
case let .developerContent(title, action):
ManagedContentView(primaryLabel: title, offerState: .custom(title: "Request"), offerAction: action) {
Image("house")
}
}
}
.managedContentStyle(.compact)
.task { await viewModel.getApps() }
}
}
I already configured an entitlement for this UI
<?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.developer.managed-app-distribution.install-ui</key>
<array>
<string>managed-app</string>
</array>
</dict>
</plist>
However the screen keeps blank with an error message "Error registering for message: [App catalog changed]: An unspecified, unrecoverable error occurred." on executing ManagedAppLibrary.currentDistributor.availableApps
And the console log probably implies that this playground app (MDM Agent for SwiftUI) should be available on App Store and installed as managed.
Jul 16 02:20:17 iPhone MDM Agent for SwiftUI(libxpc.dylib)[1395] <Notice>: [0x105a155c0] activating connection: mach=true listener=false peer=false name=com.apple.managedappdistributiond.xpc
Jul 16 02:20:17 iPhone managedappdistributiond(libxpc.dylib)[1320] <Notice>: [0xc2a1e4dc0] activating connection: mach=false listener=false peer=true name=com.apple.managedappdistributiond.xpc.peer[1395].0xc2a1e4dc0
Jul 16 02:20:17 iPhone managedappdistributiond[1320] <Notice>: [TXNaf44] \M-p\M^_\M^P\M^O Beginning transaction (<private>)
Jul 16 02:20:17 iPhone managedappdistributiond[1320] <Notice>: Activity associated with <private>ED4BF49B
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Received request: <DMFFetchAppsRequest: 0xbdc8e48c0>, from client: <CATTaskSession: 0xbdc850aa0 { state = Connected, session = 04530509-57B9-41D3-BEBC-3F07673E8BFC, transport = <CATXPCTransport: 0xbdc96c9b0 { state = Connected }> }>
Jul 16 02:20:17 iPhone dmd(libxpc.dylib)[169] <Notice>: [0xbdc1ab700] activating connection: mach=true listener=false peer=false name=com.apple.accountsd.accountmanager
Jul 16 02:20:17 iPhone accountsd(AccountsDaemon)[112] <Notice>: "<private> (<private>) received"
Jul 16 02:20:17 iPhone accountsd(libxpc.dylib)[112] <Notice>: [0xcc2804f00] activating connection: mach=false listener=false peer=true name=com.apple.accountsd.accountmanager.peer[169].0xcc2804f00
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Add operation: <DMDFetchAppsOperation: 0xbdc360000 { name = (null), ID = 4161DF16-B5EE-4C2F-AFC7-ED66C9EF6216, state = A-- [0], completed = -1/-1 }>
Jul 16 02:20:17 iPhone dmd(libxpc.dylib)[169] <Notice>: [0xbdc1ab700] invalidated because the current process cancelled the connection by calling xpc_connection_cancel()
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Operation will start: <DMDFetchAppsOperation: 0xbdc360000 { name = (null), ID = 4161DF16-B5EE-4C2F-AFC7-ED66C9EF6216, state = A-- [0], completed = -1/-1 }>
Jul 16 02:20:17 iPhone dmd(Accounts)[169] <Notice>: "The connection to ACDAccountStore was invalidated."
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Fetch apps with bundle ids: ( "com.companyname.MDM-Agent-for-SwiftUI"
), store item id: (null)
Jul 16 02:20:17 iPhone dmd(AppStoreDaemon)[169] <Notice>: [ASDUpdatesService]: getManagedUpdatesWithCompletionBlock
Jul 16 02:20:17 iPhone accountsd(libxpc.dylib)[112] <Notice>: [0xcc2804f00] invalidated after getting a no-senders notification - client is gone
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [XPCServiceEntitlements]: We have the entitlement: com.apple.itunesstored.private for pid: 169 result: 1
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [8D8ED625] getManagedUpdates requested for client: com.apple.dmd
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [8D8ED625] Returning 0 available and 0 recent update(s)
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [8D8ED625] getManagedUpdates completed successfully
Jul 16 02:20:17 iPhone dmd(AppStoreDaemon)[169] <Notice>: [ASDUpdatesService]: getUpdatesWithCompletionBlock
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [XPCServiceEntitlements]: We have the entitlement: com.apple.itunesstored.private for pid: 169 result: 1
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [C7CA1AFD] getUpdates requested for client: com.apple.dmd
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [C7CA1AFD] Returning 0 available and 0 recent update(s)
Jul 16 02:20:17 iPhone appstored[189] <Notice>: [C7CA1AFD] getUpdates completed successfully
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Lifecycle is not stale for bundle ID: com.companyname.MDM-Agent-for-SwiftUI
Jul 16 02:20:17 iPhone dmd[169] <Notice>: Operation will finish: <DMDFetchAppsOperation: 0xbdc360000 { name = (null), ID = 4161DF16-B5EE-4C2F-AFC7-ED66C9EF6216, state = AE- [0], completed = -1/-1 }>
Jul 16 02:20:17 iPhone managedappdistributiond[1320] <Error>: Hosting app <private> with persona <private> is not managed
Jul 16 02:20:17 iPhone managedappdistributiond[1320] <Error>: Error in <private>: An unspecified, unrecoverable error occurred.
Jul 16 02:20:17 iPhone managedappdistributiond[1320] <Notice>: [TXNaf44] \M-p\M^_\M^P\M^O Ending transaction (<private>) (<private>)
Jul 16 02:20:17 iPhone MDM Agent for SwiftUI(ManagedAppDistribution)[1395] <Error>: Error registering for message: [App catalog changed]: An unspecified, unrecoverable error occurred.
So, how can we develop and debug ManagedAppDistribution?
(NOTE the test device is supervised and managed using DDM.)