OSX ve iOS için bir uygulamam var ve ikisi de aralarında temel verileri paylaşmak için iCloud kullanıyor. IPhone'da değişiklikler yaptığımda onları OSX uygulamasında görebilirim ve her iki uygulamada da NSPersistentStoreDidImportUbiquitousContentChangesNotification
çağrılır, böylece iOS -> Mac iyi çalışır. Ancak Mac uygulamasında bazı değişiklikler yaptığımda onları iPhone'da göremiyorum. IPhone asla NSPersistentStoreDidImportUbiquitousContentChangesNotification
'u çağırmaz. Mac'i değiştirebilmemin tek yolu iPhone'da biraz değişiklik yapmak. Sonra tüm değişiklikleri görebilirim. Her iki projede de iCloud tümleştirmesi aynıdır. Çekirdek veri veri modeli aynıdır. Haklar da aynıdır. http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/iCloud Çekirdek Veri paylaşımı OSX ve iOS arasında
Neden iPhone bazı değişiklik yapmak kadar Mac değişiklikleri almıyor iPhone geçerli:
benim kod bu kütüphaneye dayanmaktadır Tüm? Herhangi bir fikir?
kullanıcı zaten iCloud bir dosya olup olmadığını kontrol iCloud sağlayan benim app
başka soru. Dosya mevcutsa, kullanıcı iCloud dosyasından temel verileri geri yüklemeyi seçebilir veya yerel mağazadan yeni kopya başlatabilir. Bu kodu kullanmak yeni bir kopya başlatmak için: her şey iyi iş gibi görünüyor tek cihazdan bu Doing
- (void)startNewCopy
{
[self removeICloudStore];
[self moveStoreToIcloud];
}
- (void)removeICloudStore
{
BOOL result;
NSError *error;
// Now delete the iCloud content and file
result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:[self icloudStoreURL]
options:[self icloudStoreOptions]
error:&error];
if (!result)
{
NSLog(@"Error removing store");
}
else
{
NSLog(@"Core Data store removed.");
// Now delete the local file
[self deleteLocalCopyOfiCloudStore];
}
}
- (void)deleteLocalCopyOfiCloudStore {
// We need to get the URL to the store
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:[self localUbiquitySupportURL] error:&error];
}
- (void)moveStoreToIcloud
{
// Open the store
NSPersistentStore *sourceStore = [[_persistentStoreCoordinator persistentStores] firstObject];
if (!sourceStore)
{
NSLog(@" failed to add old store");
}
else
{
NSLog(@" Successfully added store to migrate");
NSError *error;
id migrationSuccess = [_persistentStoreCoordinator migratePersistentStore:sourceStore toURL:[self icloudStoreURL] options:[self icloudStoreOptions] withType:NSSQLiteStoreType error:&error];
if (migrationSuccess)
{
NSLog(@"Store migrated to iCloud");
_persistentStoreCoordinator = nil;
_managedObjectContext = nil;
// Now delete the local file
[self deleteLocalStore];
}
else
{
NSLog(@"Failed to migrate store: %@, %@", error, error.userInfo);
}
}
}
- (void)deleteLocalStore
{
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:[self localStoreURL] error:&error];
}
ama birden fazla cihaz ile bu çalıştığımda bazı hatalar alıyorum.
Örnek:
İki aygıtım var. İlki iCloud'a bağlı değil, ikincisi iCloud'a bağlı. Ben iCloud etkinleştirdiğinizde birinci cihaz olarak Ben startNewCopy
belirledikten sonra ikinci cihazda bu hatayı alıyorum:
NSPersistentStoreCoordinatorStoresDidChangeNotification
CoreData: Ubiquity: Librarian returned a serious error for starting downloads Error Domain=BRCloudDocsErrorDomain Code=5 "The operation couldn’t be completed. (BRCloudDocsErrorDomain error 5 - No document at URL)"
hata önce hiçbir zaman denir.
Bu bildirim için benim kodudur:
Ben iCloud içeriği kaldırıldığını algılamak ve yukarıdaki hatayı almamak nasıl- (void)processStoresDidChange:(NSNotification *)notification
{
NSLog(@"processStoresDidChange");
// Post notification to trigger UI updates
// Check type of transition
NSNumber *type = [notification.userInfo objectForKey:NSPersistentStoreUbiquitousTransitionTypeKey];
//NSLog(@" userInfo is %@", notification.userInfo);
//NSLog(@" transition type is %@", type);
if (type.intValue == NSPersistentStoreUbiquitousTransitionTypeInitialImportCompleted) {
NSLog(@" transition type is NSPersistentStoreUbiquitousTransitionTypeInitialImportCompleted");
} else if (type.intValue == NSPersistentStoreUbiquitousTransitionTypeAccountAdded) {
NSLog(@" transition type is NSPersistentStoreUbiquitousTransitionTypeAccountAdded");
} else if (type.intValue == NSPersistentStoreUbiquitousTransitionTypeAccountRemoved) {
NSLog(@" transition type is NSPersistentStoreUbiquitousTransitionTypeAccountRemoved");
} else if (type.intValue == NSPersistentStoreUbiquitousTransitionTypeContentRemoved) {
NSLog(@" transition type is NSPersistentStoreUbiquitousTransitionTypeContentRemoved");
}
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
if (type.intValue == NSPersistentStoreUbiquitousTransitionTypeContentRemoved) {
[self deleteLocalStore];
_persistentStoreCoordinator = nil;
_managedObjectContext = nil;
NSLog(@" iCloud store was removed! Wait for empty store");
}
// Refresh user Interface
[[NSNotificationCenter defaultCenter] postNotificationName:@"notiIcloud" object:@"storeChanged"];
}];
}
?
Bu, sorunuzu gerçekten yanıtlamıyor, ancak Core Data'yı uzun süre önce iCloud desteği ile kullanmayı bıraktım. Daha sonra kendi senkronizasyonumu yazdım ama biraz kısıtlıydı. Sonra da Ensembles'i (http://www.ensembles.io) buldum ve o zamandan beri kullanıyordum. Benim için harika oldu. Açık kaynak kodlu bir sürümü var. Yanıt için –
Thx, ancak elmadan standart iCloud desteğini kullanmayı tercih ediyorum. – user3065901
Size iyi şanslar! –