gpt4 book ai didi

iphone - 如何让 SQLITE 数据库文件在 DropBox 中同步?

转载 作者:行者123 更新时间:2023-12-02 04:30:44 25 4
gpt4 key购买 nike

我正在开发一个 iPad 应用程序。在这里,我想将整个数据库文件上传到 dropbox。我在 google 上搜索,但没有找到合适的解决方案。我使用以下代码来创建数据库。

-(BOOL) createDatabaseFile
{
NSString *docsDir;
NSArray *dirPaths;
NSFileManager *filemgr = [NSFileManager defaultManager];
BOOL successMsg = YES;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];

// Build the path to the database file
self.detaildatabasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent:@`"Database.sql"`]];
// Check For Existence of the database file
if ([filemgr fileExistsAtPath:self.detaildatabasePath])
{
//File Exists At The Path
}
else
{
//Since file is not available at the path create a Database File
successMsg = [filemgr createFileAtPath:self.detaildatabasePath contents:[NSData data] attributes:nil];
}
return successMsg;
}

那么我怎样才能获得我的“Database.sql”文件。请不要将其视为重复的问题。我浪费了一天的时间进行谷歌搜索,但没有找到解决方案。请指导我。

提前致谢

最佳答案

要将文件上传到 Dropbox,您需要 Dropbox SDK - https://www.dropbox.com/developers/sync/sdks/ios (如何将Dropbox.framework添加到您的项目中)

然后您可以上传文件:

-(void) createBackupInDropbox {
NSString *filename = @"backup.sqlite"; //File name in DropBox
NSString *destDir = @"/backups"; //Destination path in DropBox
NSString *fromPath = @"..."; //local path to your DB file
/*
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
fromPath = [docsPath stringByAppendingPathComponent:@"my_database.sqlite"];
*/

[[self restClient] deletePath:[NSString stringWithFormat:@"%@/%@", destDir, filename]]; //delete file if you need to replace it
[[self restClient] uploadFile:filename toPath:destDir
withParentRev:nil fromPath:fromPath];
}

控制上传过程:

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
from:(NSString*)srcPath metadata:(DBMetadata*)metadata {
NSLog(@"File uploaded successfully to path: %@", metadata.path);
}

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
[waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
NSLog(@"File upload failed with error - %@", error);
}

- (void)restClient:(DBRestClient*)client uploadProgress:(CGFloat)progress forFile:(NSString *)destPath from:(NSString *)srcPath
{

}

和restClient方法:

- (DBRestClient *)restClient {
if (!restClient) {
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
}
return restClient;
}

关于iphone - 如何让 SQLITE 数据库文件在 DropBox 中同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17703153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com