有个项目需要对数据进行云端备份,调研了几家云备份数据服务平台后决定采用微软Azure的服务,主要原因是提供了APP Service这样可以进行脱机数据同步的服务。
https://docs.azure.cn/zh-cn/app-service-mobile/app-service-mobile-ios-get-started-offline-data
1. 创建Azure SQL数据库
2. 创建APP Service,选择MobileService,命名为“Test”
3. 在“Test”中选择Quick Start,选择刚才创建SQL数据库表,然后Azure会为我们自动创建一个TodoItem的数据库表
4.下载示例程序iOS Swift版
5.在示例程序中有一个coredata的数据库文件,包含id, createdAt, updatedAt, deleted四个默认的属性,还有一个complete的自定义属性
6. 看一下APPDelegate文件,相比默认的文件,添加了
// MARK: - Core Data stack
lazy var applicationDocumentsDirectory: URL = {
// The directory the application uses to store the Core Data store file.
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return urls[urls.count-1]
}()
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = Bundle.main.url(forResource: "QSTodoDataModel", withExtension: "momd")!
ret