iphone - 从 Dropbox 下载 sqlite 数据库

标签 iphone xcode dropbox

我正在尝试使用直接链接作为源路径从 Dropbox 下载 sqlite 数据库,然后将其保存到应用程序的文档文件中。这只是更新数据库的一种方法,而无需更新应用程序。

当我在下载之前检查文件是否存在时,该文件不可见。

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *sourceDBPath = @"https://www.dropbox.com/s/868vvg7uremst9n/Data.sqlite?dl=1";

if ([fileManager fileExistsAtPath:sourceDBPath])
{

NSData *dbFile = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"https://www.dropbox.com/s/868vvg7uremst9n/Data.sqlite?dl=1"]];

NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle]  resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"Database.sqlite"];


[dbFile writeToFile:filePath atomically:YES];
}

即使我使用文件的直接链接,我是否需要将 Dropbox SDK 集成到我的应用中?

最佳答案

嗯,该链接肯定有效,而且不,您不需要链接 Dropbox 和您的应用程序即可正常工作。

https 和 ios 存在一些问题,详细信息如下:

iOS 5 的 TLS 实现已升级,支持 TLS 协议(protocol)版本 1.2。一些不合规的 TLS 服务器实现不实现 TLS 1.2,更重要的是,不会正常降级到受支持的协议(protocol)版本。因此,您可能会发现,针对 iOS 5 SDK 构建的某些 TLS 客户端应用程序可能无法连接到某些 TLS 服务器,而针对早期版本的 iOS SDK 构建的同一应用程序却可以连接。

Excerpted from...

更新。

但是,我只是尝试使用以下代码检索它:

NSString *dropboxHttpsUrl = @"https://www.dropbox.com/s/868vvg7uremst9n/Data.sqlite?dl=1";
NSData *dbFile = [[NSData alloc] initWithContentsOfURL:
                      [NSURL URLWithString:dropboxHttpsUrl]];

if(dbFile) {
   NSLog(@"%i", [dbFile length]);
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"test.db"];
   [dbFile writeToFile:appFile atomically:YES];
   NSLog(@"%@", appFile);
}else{
   NSLog(@"nothing got retrieved");
}

我能够获取数据库并看到空的Example表和架构。

只需以更标准的方式构建文档路径:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"test.db"];

不要这样做:

NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle]  resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];

这可能会将其保存到错误的位置,或者更糟糕的是根本不保存。

关于iphone - 从 Dropbox 下载 sqlite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13999497/

相关文章:

ios - Cordova build ios 没有通过,我没有收到任何错误。

ios - 在没有登录提示的情况下自动登录 Core Api 上的 Dropbox 帐户

java - 用于纯 Java 的 Dropbox Sync API 或 Core API

iphone - 如何使用 TouchXML 或其他替代方案解析 HTML

iphone - 属性与实例变量

ios - uitableview 中的 Uilabel 在调试模拟器颜色混合层中不显示不透明而不透明

ios - “[CP] Embed Pods Frameworks”构建脚本排序

javascript - 如何使用 JavaScript 嵌入 Dropbox 中的视频?

iphone - iOS 触摸换图

iphone - 指定图像到 4 英寸 iOS 设备