PhotoKit request AddOnly authorization error:Domain=com.apple.photos.error Code=46104

What is Error Domain=com.apple.photos.error Code=46104 mean?
This error appears when I try to create an album on iOS14.

case:
User first gives AddOnly authorization and then gives ReadWrite authorization.
After I get the ReadWrite authorization, create an album.

code reference:
Code Block Objective-C
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetCollectionChangeRequest *request = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:albumName] 
albumPlaceholder = [request placeholderForCreatedAssetCollection];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
// success is NO, error is "Error Domain=com.apple.photos.error Code=46104" 
}];

The supplementary log information for the above question is as follows:
Code Block Objective-C
2020-08-17 11:28:19.470871+0800 XXXX[4255:1139139] CoreData: XPC: Unable to connect to server with options { NSXPCStoreServerEndpointFactory = "<PLXPCPhotoLibraryStoreEndpointFactory: 0x280ce8760>"; skipModelCheck = 1;}
2020-08-17 11:28:19.479533+0800 XXXX[4255:1139139] CoreData: XPC: Unable to load metadata: Error Domain=NSCocoaErrorDomain Code=134060 "关键数据出错。" UserInfo={Problem=Unable to send to server; failed after 8 attempts.}
2020-08-17 11:28:19.483149+0800 XXXXX[4255:1139139] [error] error: addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134060)
CoreData: error: addPersistentStoreWithType:configuration:URL:options:error: returned error NSCocoaErrorDomain (134060)
CoreData: annotation: userInfo:CoreData: annotation: Problem : Unable to send to server; failed after 8 attempts.
CoreData: annotation: storeType: NSXPCStoreCoreData: annotation: configuration: (null)
CoreData: annotation: URL: file:///var/mobile/Media/PhotoData/Photos.sqlite
CoreData: annotation: options:
CoreData: annotation: NSXPCStoreServerEndpointFactory : <PLXPCPhotoLibraryStoreEndpointFactory: 0x280ce8760>CoreData: annotation: skipModelCheck : 1
2020-08-17 11:28:19.485049+0800 XXXXX[4255:1139139] [Generic] Failed to connect to XPC PhotoLibraryStore file:///var/mobile/Media/PhotoData/Photos.sqlite with options { NSXPCStoreServerEndpointFactory = "<PLXPCPhotoLibraryStoreEndpointFactory: 0x280ce8760>"; skipModelCheck = 1;}: Error Domain=NSCocoaErrorDomain Code=134060 "关键数据出错。" UserInfo={Problem=Unable to send to server; failed after 8 attempts.}
2020-08-17 11:28:19.485565+0800 XXXXX[4255:1139139] [Migration] Failed to configure PSC for library file:///var/mobile/Media/: Error Domain=NSCocoaErrorDomain Code=134060 "关键数据出错。" UserInfo={Problem=Unable to send to server; failed after 8 attempts.}
2020-08-17 11:28:19.485943+0800 XXXXX[4255:1139139] [LibraryBundle] Unable to create PLLibraryBundleLogInfo because PSC is nil


There is another problem. When saving the video, if the AddOnly permission is taken first and then the ReadWrite permission is taken, the performChanges method will freeze for more than 10 seconds before calling the completionHandler. The following is the log information:
Code Block Objective-C
[Generic] Failed to connect to XPC PhotoLibraryStore file:///var/mobile/Media/PhotoData/Photos.sqlite with options {
NSXPCStoreServerEndpointFactory = "<PLXPCPhotoLibraryStoreEndpointFactory: 0x280700d00>";

These problems only occur during a cold launch when the AddOnly permission is taken first and then the ReadWrite permission is taken. Whether the app only takes the AddOnly permission, only takes the ReadWrite permission, or closes the app after authorization and reopens it will not happen.



Post not yet marked as solved Up vote post of THUYu Down vote post of THUYu
3.4k views
  • @THUYu,

    hi, is there any solution or workaround to solve it?

Add a Comment

Replies

I thought I am the only one who is facing this error, I confirm the issue is exist also in a very small isolated piece of code,
  • give AddOnly permission

  • try to obtain ReadWrite permissions

  • fetch albums (fail)

and even worse the photoLibraryDidChange never get called in this scenario,

close and reopen the app, everything working as expected.

(UIActivityViewController save image or video, UIImageWriteToSavedPhotosAlbum, PHPhotoLibrary performChanges, ...) all of them will cause the same exact issue when used to obtain AddOnly permission first then try to get a ReadWrite permission

It seems it is an iOS 14.0 bug, (and I also confirm it is still exist with iOS 14.0.1)
Post not yet marked as solved Up vote reply of ams Down vote reply of ams
The same bug also in iOS 14.2 right? At least I have it inside Xcode 12.2 (testing with simulator and device).
Same thing is happening to me. Has anyone found a workaround?
I am also having the exact same issue.
I see the same thing in iOS 14.5 (Xcode beta 3)

same issue

Same issue.

Same problem. Easy to reproduce with steps above.

There any Update on this issue?

Same issue.

Seems to work in iOS 15, so this is what I'm doing now:

requestAuthorization {
  /// got permissions
}

func requestAuthorization(completion: @escaping (() -> Void)) {
  if #available(iOS 15, *) { /// works, so use `addOnly`
    PHPhotoLibrary.requestAuthorization(for: .addOnly) { (status) in
      if status == .authorized || status == .limited {
        completion()
      }
    }
  } else if #available(iOS 14, *) { /// use `readWrite` directly instead. This will ask for both read and write access, but at least it doesn't crash...
    PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in
      if status == .authorized || status == .limited {
        completion()
      }
    }
  } else { /// for older iOS just do `requestAuthorization`
    PHPhotoLibrary.requestAuthorization { (status) in
      if status == .authorized {
        completion()
      }
    }
  }
}
Add a Comment