Ale*_*eph 2 macos icloud swiftui
我有一个使用 iCloud 进行同步的 iOS 和 iPadOS 应用程序。它们在 App Store 中,并且数据库已投入生产。它们的工作原理与广告中所宣传的一样。
我还编写了一个使用 iCloudkit 的 macOS 应用程序,它设置的容器NSPersistentCloudKitContainer
和合并策略都设置正确。我还检查了应用程序的配置文件和证书是否正常,以及应用程序的权限。
Apple 签署了该应用程序,但是它不与 iCloud 同步,我不明白为什么。我在 Mac 上检查了 iCloud,该应用程序就在那里,设置为同步。我是否已经阅读了几篇文章并尝试了所有可能的解决方案,包括退出并重新登录、重建应用程序等。
有一件事,当我删除一个项目时,应用程序需要一些时间才能对其做出反应,就好像它正在尝试连接一样。我尝试使用 TCPDump 和其他工具来检查连接问题,但我找不到尝试连接的应用程序。
我拍了一些不同配置的屏幕截图等,以便您也可以看到,但是有人遇到过这个问题吗?您知道可能的解决方案吗?
谢谢。
Mac 上的 iCloud 设置
开发者站点上的配置文件
应用程序的项目设置(是的,容器/数据库与 iOS 应用程序相同)
代码在persistance.swift
:
import CoreData
struct PersistenceController {
static let shared = PersistenceController()
static var preview: PersistenceController = {
let result = PersistenceController(inMemory: true)
let viewContext = result.container.viewContext
for _ in 0..<10 {
let newBolt = Jot(context: viewContext)
newBolt.id = UUID()
newBolt.text = "random"
}
do {
try viewContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
return result
}()
let container: NSPersistentCloudKitContainer
init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "Simple_Bolt")
let description = container.persistentStoreDescriptions.first
description?.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
description?.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*eph 11
嗯,答案很简单,但很难找到。似乎当您将 Core Data 应用程序转换为与 CloudKit 一起使用时,您需要添加CloudKit.framework
到该Frameworks, Libraries, and Embedded Content
部分。如果没有它,应用程序在调试模式下运行时(通过 Xcode)可以工作,但一旦投入生产、签名和公证,就无法工作。即使您拥有正确的权利,所有权利都指向生产等。
归档时间: |
|
查看次数: |
528 次 |
最近记录: |