简体   繁体   English

iOS应用程序在设备设置页面中禁用了iCloud驱动器并关闭了iCloud持久存储

[英]iOS app disable iCloud drive(off) in device settings page and get iCloud persistentStore

I am developing iOS app with iCloud sync. 我正在使用iCloud sync开发iOS应用。 I stored datas using core data with support of iCloud sync then if i switch off iCloud drive in device settings, My app could not read stored data in UbiquityContainer. 我使用支持iCloud同步的核心数据存储数据,然后,如果我在设备设置中关闭了iCloud驱动器,则我的应用程序无法读取UbiquityContainer中的存储数据。 Now i want to migrate iCloud persistence store data to local/other place when user iCloud drive is off. 现在,当用户iCloud驱动器关闭时,我想将iCloud持久性存储数据迁移到本地/其他地方。 But i could not get iCloud persistence store. 但是我无法获得iCloud持久性存储。 I tried following methods not working. 我尝试了以下不起作用的方法。

NSPersistentStore *result = [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                               configuration:nil
                                         URL:storeURL
                                     options:options
                                       error:nil];

Result is return nil. 结果是返回nil。 Because i could not get exact storeURL of ubiquity store. 因为我无法获得普遍存在的商店的精确storeURL。

 NSURL *iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:@"iCloud.com.Identifier"];

Gives nil instead of url.Is there a way to get iCloud store after switch off iCloud drive. 提供nil而不是url。关闭iCloud驱动器后是否有办法获取iCloud存储。 Because i could not display stored in datas. 因为我无法显示存储在数据中。

See the following extract from Apple documents ( https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesignForCoreDataIniCloud.html ) 请参阅以下Apple文档摘录( https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesignForCoreDataIniCloud.html

Design the Launch Sequence for Your iCloud Core Data App 为您的iCloud Core Data App设计启动顺序

When you adopt iCloud, take special care when designing the launch sequence for your app. 当您采用iCloud时,在设计应用程序的启动顺序时要格外小心。 The following factors come into play and you must account for them: 以下因素起作用,您必须考虑它们:

  • The user might or might not have previously indicated a preference to use iCloud in your app; 用户先前可能已经或未曾指示过偏好在您的应用程序中使用iCloud; the local instance of your app might or might not have already established its initial store in a ubiquity container. 您应用的本地实例可能已经或可能尚未在普遍存在的容器中建立其初始存储。

    As a first step in your launch sequence, read the local user defaults database using the shared NSUserDefaults object. 作为启动序列的第一步,请使用共享的NSUserDefaults对象读取本地用户默认数据库。 During operation of your app, use that object to save user choices that you'll need on next launch. 在应用程序运行期间,使用该对象保存下次启动时所需的用户选择。

  • The user might log out of iCloud or switch to another account. 用户可能会注销iCloud或切换到另一个帐户。

    If a user logs out of iCloud, or switches to another account, the ubiquity containers for the previously used account are no longer available to your app. 如果用户注销iCloud或切换到另一个帐户,则以前使用的帐户的普遍存在的容器将不再对您的应用程序可用。

  • The local Core Data store might be newer or older than the store on 本地核心数据存储区可能比上的存储区新或旧
    another device owned by the same user. 同一用户拥有的另一台设备。

    During app launch, Core Data might need to reconcile the local store with change logs from iCloud. 在应用启动期间,Core Data可能需要将本地存储与iCloud的更改日志进行协调。 This can involve detection and resolution of duplicate records and conflicts. 这可能涉及检测和解决重复记录和冲突。 Testing is critical. 测试至关重要。 To get started with some tips, refer to Testing and Debugging Your iCloud App as well as Best Practices and Troubleshooting in iCloud Programming Guide for Core Data. 要开始使用一些技巧,请参阅《 iCloud应用程序的测试和调试》以及《 iCloud核心数据编程指南》中的最佳实践和故障排除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM