Error adding private sharing PCS to public sharing PCS for share

I am attempting to use the open ai image API and send images. Unfortunately, they don’t let you send image data directly, instead, you have to save and share the image to the cloud, and send their API a link.

I am trying to save the image via icloud, and make it public.

Here are the Dashboard configuration steps I’ve taken

Here is my code:

import CloudKit
import Foundation

extension Data {
    func uploadToCloudKit(completion: @escaping (Result<URL, Error>) -> Void) {
        do {
            let containerIdentifier = try String.iCloudContainerIdentifier()
            let container = CKContainer(identifier: containerIdentifier)
            let publicDatabase = container.publicCloudDatabase

            // Create a record
            let record = CKRecord(recordType: "Image")

            // Save the image data to a temporary file
            let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
            try self.write(to: tempURL)

            // Create a CKAsset with the file URL
            let imageAsset = CKAsset(fileURL: tempURL)
            record["image"] = imageAsset

            // Save the record to CloudKit
            publicDatabase.save(record) { savedRecord, error in
                // Delete the temporary file
                try? FileManager.default.removeItem(at: tempURL)

                if let error = error {
                    completion(.failure(GenericError("Error uploading image: (error.localizedDescription)")))
                    return
                }

                guard let savedRecord = savedRecord else {
                    completion(.failure(GenericError("Failed to save record without error")))
                    return
                }

                let share = CKShare(rootRecord: record)
                let container = CKContainer.default()
                let modifyRecordsOperation = CKModifyRecordsOperation(recordsToSave: [record, share])
                modifyRecordsOperation.modifyRecordsCompletionBlock = { savedRecords, deletedIds, error in
                    DispatchQueue.main.async {
                        if let error = error as? CKError {
                            let genericError: GenericError

                            switch error.code {
                            case .networkUnavailable, .networkFailure:
                                genericError = GenericError("Network issues: (error.localizedDescription)")
                            case .quotaExceeded:
                                genericError = GenericError("Quota exceeded: (error.localizedDescription)")
                            case .partialFailure:
                                if let partialErrors = error.partialErrorsByItemID {
                                    let partialErrorMessages = partialErrors.map { "Partial error for recordID ($0.key): ($0.value.localizedDescription)" }
                                    genericError = GenericError(partialErrorMessages.joined(separator: ", "))
                                } else {
                                    genericError = GenericError("Partial failure without specific errors: (error.localizedDescription)")
                                }
                            case .serverRecordChanged:
                                genericError = GenericError("Server record changed: (error.localizedDescription)")
                            case .notAuthenticated:
                                genericError = GenericError("Not authenticated: (error.localizedDescription)")
                            case .permissionFailure:
                                genericError = GenericError("Permission failure: (error.localizedDescription)")
                            default:
                                genericError = GenericError("Other error: (error.localizedDescription)")
                            }

                            completion(.failure(genericError))
                        } else if let shareURL = share.url {
                            completion(.success(shareURL))
                        } else {
                            completion(.failure(GenericError("Failed to save record without error")))
                        }
                    }
                }
                publicDatabase.add(modifyRecordsOperation)
            }
        } catch {
            completion(.failure(error))
        }
    }
}

When I po the error I get:

(lldb) po genericError
▿ GenericError
  - message : "Partial error for recordID <CKRecordID: 0x6000010dcf20; recordName=2D6350E1-F1BC-4CE9-89CE-35A1E52D259C, zoneID=_defaultZone:__defaultOwner__>: Record <CKRecordID: 0x1239aa420; recordName=2D6350E1-F1BC-4CE9-89CE-35A1E52D259C, zoneID=_defaultZone:__defaultOwner__> will not be saved because of previous error in atomic zone, Partial error for recordID <CKRecordID: 0x6000010dcfe0; recordName=Share-E804AED9-AC79-445A-96B4-27EB2647A1AD, zoneID=_defaultZone:__defaultOwner__>: Error adding private sharing PCS to public sharing PCS for share <CKRecordID: 0x1238956b0; recordName=Share-E804AED9-AC79-445A-96B4-27EB2647A1AD, zoneID=_defaultZone:__defaultOwner__>: <CKError 0x122721e30: "Internal Error" (5005); "You can't add a nil share PCS to a record PCS">"

I am not sure what else needs to be done, but I keep getting this error.

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