ストレージに Core Data を使用する iOS 7 のみのアプリがあり、iCloud をアプリに切り替えて使用しています。
ユーザーがアプリ内からiCloudをオフにした場合のiCloudストアからローカルストアへの移行を除いて、iCloud統合のすべての側面が機能しています.
を使用するException Breakpoint
と、アプリが次のようにクラッシュします。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM replaceObjectAtIndex:withObject:]: object cannot be nil'
これは " migratePersistentStore
" コードでクラッシュしています。
これを実行するコードは次のとおりです。
- (void)migrateiCloudStoreToTheLocalStoreAfterUserTurnedOffiCloudInSettings
{
// So we can see what's going on, we'll write out the current store URL before the migration
NSURL *storeURL = [self.persistentStoreCoordinator.persistentStores.lastObject URL];
NSLog(@"Current Store URL (before iCloud to Local migration): %@", [storeURL description]);
// NSPersistentStore *currentStore = self.persistentStoreCoordinator.persistentStores.lastObject;
NSPersistentStore *currentStore = [[self.persistentStoreCoordinator persistentStores] firstObject];
// We'll create a new URL
NSURL *localURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Envylope.sqlite"];
NSDictionary *localStoreOptions = nil;
localStoreOptions = @{ NSPersistentStoreRemoveUbiquitousMetadataOption : @YES,
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES};
NSError *error = nil;
[self.persistentStoreCoordinator migratePersistentStore:currentStore
toURL:localURL
options:localStoreOptions
withType:NSSQLiteStoreType error:&error];
NSLog(@"Current Store URL (after iCloud to Local migration): %@", [localURL description]);
// We'll write out a NSError here to see if there were any errors during the migration
NSLog(@"Error from iCloud to local migration %@", error);
// We'll just do a quick check to make sure are no errors with this procedure.
NSLog(@"Erros's after all of that %@", error);
NSLog(@"Current Store URL (after everything): %@", [localURL description]);
[self removeCloudObservers];
}
問題
上記の行で、上記のエラーでアプリがクラッシュしますmigratePersistentStore
。これを機能させるために何をすべきかわかりません。
currentStore のコメントアウトされたコードは、firstObject の代わりに lastObject もチェックしようとしたことを示しており、どちらの場合も同じ結果が得られています。
ユーザーがiCloudを使用しているが使用しないことを選択した場合、データをローカルに移行する必要があることを確認したいので、ローカルからiCloudにクラッシュすることはありません。
この ( Migrate Persistant Store Crash ) スタック オーバーフローの質問は完璧に適合するようですが、まず回答が受け入れられず、質問者からコードが機能するという確認がなく、そのコードが機能しませんでした私のため; 単純にデータを削除しました。
これに関するガイダンスをいただければ幸いです。