Skip to content
DnsLister Forum

Where domain hunters compare notes

macOS PhotoKit works in local Release but fails in TestFlight with XPC error 4099

I'm developing a macOS app using Kotlin Multiplatform / Kotlin Native + Compose Desktop. The app needs to read photos from the user's System Photo Library using PhotoKit.

I'm seeing a strange difference between my local Release build and the TestFlight build.

Local Release

The following works normally:

val options = PHFetchOptions() val result = PHAsset.fetchAssetsWithMediaType( PHAssetMediaTypeImage, options ) println("count = ${result.count}") 

The local Release build can fetch the photo assets successfully.

I also see:

activating connection: mach=true listener=false peer=false name=com.apple.photos.service Using low priority assetsd XPC client Using high priority assetsd XPC client 

TestFlight

The exact same code returns 0 assets.

The app has Photos permission, and TCC reports:

kTCCServicePhotos ReqResult(Auth Right: Allowed (User Consent)) 

The final TestFlight app also contains:

<key>com.apple.security.personal-information.photos-library</key> <true/> 

However, when the fetch is triggered, I see:

activating connection: mach=true listener=false peer=false name=com.apple.photos.service failed to do a bootstrap look-up: xpc_error=[159: Unknown error: 159] XPC connection error to assetsd Error Domain=NSCocoaErrorDomain Code=4099 

Later PhotoKit reports:

PHPhotosErrorDomain Code=41002 Underlying NSCocoaErrorDomain Code=4099 

I also saw:

PHFetchResult init with invalid config: query has nil fetch request 

So it looks like the failure happens before the actual asset query, while PhotoKit is trying to connect to the Photos service / assetsd.

Things I've already checked

  • PHAccessLevelReadWrite
  • PHPhotoLibrary.authorizationStatusForAccessLevel()
  • requestAuthorizationForAccessLevel()
  • Photos TCC permission — explicitly Allowed
  • com.apple.security.personal-information.photos-library
  • Bundle ID
  • Team ID
  • Final TestFlight entitlements
  • PHFetchOptions
  • fetchAssetsWithMediaType(PHAssetMediaTypeImage, ...)
  • The Photos Library itself works normally in Photos.app
  • The same PhotoKit code works in local Release

I'm using Kotlin Native Objective-C interop for PhotoKit rather than Swift/Objective-C.

Has anyone seen com.apple.photos.service failing to bootstrap with xpc_error=159 / NSCocoaErrorDomain Code=4099 only for a TestFlight build?

I'm especially interested in whether there is some additional entitlement, sandbox configuration, or TestFlight-specific behavior for PhotoKit that I'm missing.

Any pointers would be appreciated.

Source: r/macosprogramming · by /u/NoCodeNoBugs_Dev

Leave a Reply

Your email address will not be published. Required fields are marked *