繁体   English   中英

备份iPhone应用程序sqlite3数据库数据的最佳方法是什么?

[英]what is the best way to take the backup of data of sqlite3 database of iphone application?

我想在Dropbox中备份iPhone应用程序数据库中所有数据的备份并稍后还原。这里的主要问题是应用程序中的数据太多,所以如果我使用sql查询从sqlite3数据库中获取数据并将其存储到文件中,然后再次从该文件中读取数据并将其插入数据库中。有人可以建议我如何改进它,或者最好的方法是什么?

我认为您的意思是您希望能够在用户以某种方式删除了该应用程序并再次重新安装之后恢复数据。 由于每个应用程序都会在其沙箱范围内产生影响,因此唯一明智的选择是使用服务器。 关于仅回答您的问题-正如您所描述的那样,没有办法做到。

您可以使用iCloud。 转到Itunes Connect上的应用程序管理器以生成iCloud密钥。 因此,所有数据将存储在icloud上。

我基于Dropbox的Sync API解决方案:

- (IBAction)onTouchDropboxBackup:(id)sender {

    DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];

    if (account) {

        if (![sharedDelegate filesystem]) {

            DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
            [DBFilesystem setSharedFilesystem:filesystem];
            [sharedDelegate setFilesystem:filesystem];
            [filesystem release];
        }

        DBPath *destination = [[DBPath root] childPath:kDataDBFileName];
        DBError *error = nil;

        //check presense
        DBFile *file = [[DBFilesystem sharedFilesystem] openFile:destination
                                                       error:&error];
        if (error){//not present

            [[DBFilesystem sharedFilesystem] createFile:destination
                                              error:&error];

            file = [[DBFilesystem sharedFilesystem] openFile:destination
                                                   error:&error];
        }

        if (!error) {

            [file writeContentsOfFile:[DOCUMENTS_DIR stringByAppendingPathComponent: kDataDBFileName]
                          shouldSteal:NO
                            error:&error];

            [file update:&error];
            [file close];
        }

    }else
        [[DBAccountManager sharedManager] linkFromController:self];
}

您也可以将uuid用作Web服务的键。 因此,如果使用delete应用程序并在他重新安装时,则cad下载带有密钥标识符的所有数据。

例如:

uuid = [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier];

UUID的类

重要:使用全局模式,因为它允许在应用程序之间使用uuid。

暂无
暂无

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

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