作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 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/
我是一名优秀的程序员,十分优秀!