阿波罗ios如何在磁盘上缓存数据?
我需要将数据缓存在磁盘上以便脱机查看,我在apollo ios源代码中找到ApolloSQLite,但我找不到ApolloSQLite的任何文档(我也尝试过谷歌搜索) 环境:阿波罗ios如何在磁盘上缓存数据?,ios,swift,graphql,apollo-ios,Ios,Swift,Graphql,Apollo Ios,我需要将数据缓存在磁盘上以便脱机查看,我在apollo ios源代码中找到ApolloSQLite,但我找不到ApolloSQLite的任何文档(我也尝试过谷歌搜索) 环境: Xcode 10.1 macOS 10.14.3 CocoaPods 1.5.3 Apollo (0.9.5) SQLite.swift (0.11.5) pod安装后出现太多错误: pod 'Apollo' pod 'Apollo/SQLite' 当我使用CoCoCoaPods 1.5.3时,在pod安装后缺少源代
Xcode 10.1
macOS 10.14.3
CocoaPods 1.5.3
Apollo (0.9.5)
SQLite.swift (0.11.5)
pod安装后出现太多错误:
pod 'Apollo'
pod 'Apollo/SQLite'
当我使用
CoCoCoaPods 1.5.3
时,在pod安装后缺少源代码Apollo/Core
,这会导致错误。我已经通过将CocoaPods升级到1.6.0解决了这个问题
顺便说一句,最初的问题是如何使用ApolloSQLite?,因为我还没有找到ApolloSQLite的任何文档。经过太多的搜索和查询后,我将以下步骤列出,以供其他人帮助:
使用CocoaPods管理LIB:
需要一个文件路径来保存用于缓存数据的sqlite文件。粘贴我的代码以供参考:
func temporarySQLiteFileURL() -> URL {
let applicationSupportPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!
let dbPath = applicationSupportPath + "/com.[special name].cache"
if !FileManager.default.fileExists(atPath: dbPath) {
try? FileManager.default.createDirectory(atPath: dbPath, withIntermediateDirectories: true, attributes: nil)
}
let url = URL(fileURLWithPath: dbPath)
return url.appendingPathComponent("db.sqlite3")
}
配置客户端:
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10
let url = URL(string: self.graphQLApiAddress!)!
let networkTransport = HTTPNetworkTransport(url: url, configuration: configuration)
let cache = try? SQLiteNormalizedCache(fileURL: temporarySQLiteFileURL())
let store = ApolloStore(cache: cache ?? InMemoryNormalizedCache())
self.apolloClient = ApolloClient(networkTransport: networkTransport, store: store)
完美的指南,让你开始与阿波罗。遗憾的是,文档中几乎没有关于入门的信息
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10
let url = URL(string: self.graphQLApiAddress!)!
let networkTransport = HTTPNetworkTransport(url: url, configuration: configuration)
let cache = try? SQLiteNormalizedCache(fileURL: temporarySQLiteFileURL())
let store = ApolloStore(cache: cache ?? InMemoryNormalizedCache())
self.apolloClient = ApolloClient(networkTransport: networkTransport, store: store)