the_world_21
@the_world_21 (yamato takeru)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

iCloudの認証エラー?にいて

Q&A

Closed

解決したいこと

iCloud連携するアプリを作ってみたいと思い、勉強しているのですが、
databaseからの読み込みができなくて困っています。
シミュレータでのビルドはできるのですが、立ち上げ時にdatabaseからの読み込みができなかったエラーが出ます。
エラー文を読む限り、アカウント認証の問題のようなのですが、よくわかりません。
解決方法を教えてください。

発生している問題・エラー

database読み込みエラー。
エラー文を読む限り、アカウント認証の問題っぽいです。

出ているエラーメッセージを入力

Error read country

例)

NameError (uninitialized constant World)

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

class ApplicationData:ObservableObject{
@Published var countryList : [CountryViewModel] = []
@Published var cityList : [CityViewModel] = []

var database : CKDatabase!

init(){
    let container = CKContainer(identifier: "cityList")
    database = container.privateCloudDatabase
    
    Task(priority:.high){
        await readCountries()
    }
}

    func readCountries()async {
    let predicate = NSPredicate(format: "TRUEPREDICATE") // all true
    let query = CKQuery(recordType: "Countries", predicate: predicate)
    
    do{
        let list = try await database.records(matching: query,inZoneWith: nil,desiredKeys: nil,resultsLimit: 0)
        
        await MainActor.run{
            countryList = []
            for (_,result) in list.matchResults{
                if let record = try? result.get(){
                    let newCountry = Country(name: record["name"], record: record)
                    let newItem = CountryViewModel(id: record.recordID, country: newCountry)
                    countryList.append(newItem)
                }
            }
            countryList.sort(by: {$0.countryName < $1.countryName})
        }
    } catch {
        print("Error read country \(error)")
    }
}

自分で試したこと

signing & capabilityパネルのiCloudのところではContainersの名称も赤色にはなっていないので、container名は問題ないと思います。

0

1Answer

The issue seems related to iCloud authentication or permissions. Ensure the following steps are completed:

Verify the CKContainer(identifier:) matches your iCloud container's identifier in the Apple Developer portal.
Check that the app has iCloud capabilities enabled in Signing & Capabilities.
Confirm the logged-in iCloud account on the test device has proper access to the private database.
Use the production environment only after testing works in the development environment.
Check for typos and review Apple's CloudKit documentation.https://350ppm.co.uk/services/business-plan

0Like

Your answer might help someone💌