0

アプリの Core Data に保存されたデータを作成しました。このコードはデータを作成し、アプリの Core Data に保存します。

@objc func addData(location:CLLocation, lastLocation:CLLocation, id: String) {
        
        let object = NSManagedObject(entity: self.userEntity, insertInto: self.managedContext)
                                
            object.setValue(Date(), forKey: "time")
            object.setValue(elapsedDistance, forKey: "cumulativeDistance")
            object.setValue(location.coordinate.latitude, forKey: "latitude")
            object.setValue(location.coordinate.longitude, forKey: "longitude")
            object.setValue(id, forKey: "id")
        
        // min/km
        let overallPace = (Double(elapsedSecond) / elapsedDistance) * (1000 / 60)
        
            object.setValue(overallPace, forKey: "overallPace")
            object.setValue(overallPace * 1.6, forKey: "overallPaceMile")
            object.setValue(exerciseType!, forKey: "exerciseType")
            object.setValue((elapsedDistance / 1000.0).rounded(toPlaces: 2) * 1.6, forKey: "cumulativeDistanceMile")
            dataSet.append(object)
            
        do {
            try self.managedContext.save()
                                    
            } catch {
            print("ERROR: \(error.localizedDescription)")
        }
    }

アプリのインターネット接続が切断されたため、iCloud にデータがアップロードされませんでした。インターネットが復元され、アプリが再起動されたときに同期が行われるかどうかを確認できるように、意図的にインターネットを切断しました。ただし、同期は行われませんでした。(はい、NSPersistentCloudKitContainer を使用しました。)

アプリの Core Data と iCloud の不一致をアプリに手動でチェックしてもらい、手動で同期させる機能はありますか?

4

0 に答える 0