Commit aad3af55ca62aecf3c00443edcf0f43e51bee7ee

Authored by 葛建军
1 parent 32f28146
Exists in parentassistant

适配9.0系统,数据库coredata增加 message.type字段(用来区分订购,请假等)

ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj
@@ -1273,7 +1273,7 @@ @@ -1273,7 +1273,7 @@
1273 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK", 1273 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1274 ); 1274 );
1275 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist"; 1275 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1276 - IPHONEOS_DEPLOYMENT_TARGET = 10.0; 1276 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1277 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1277 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1278 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant; 1278 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1279 PRODUCT_NAME = "$(TARGET_NAME)"; 1279 PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1303,7 +1303,7 @@ @@ -1303,7 +1303,7 @@
1303 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK", 1303 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1304 ); 1304 );
1305 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist"; 1305 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1306 - IPHONEOS_DEPLOYMENT_TARGET = 10.0; 1306 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1307 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 1307 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1308 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant; 1308 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1309 PRODUCT_NAME = "$(TARGET_NAME)"; 1309 PRODUCT_NAME = "$(TARGET_NAME)";
ParentAssistant/ParentAssistant.xcworkspace/xcuserdata/jun.xcuserdatad/UserInterfaceState.xcuserstate
No preview for this file type
ParentAssistant/ParentAssistant/AppDelegate.swift
@@ -201,11 +201,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { @@ -201,11 +201,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
201 func applicationWillTerminate(_ application: UIApplication) { 201 func applicationWillTerminate(_ application: UIApplication) {
202 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 202 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
203 // Saves changes in the application's managed object context before the application terminates. 203 // Saves changes in the application's managed object context before the application terminates.
204 - self.saveContext() 204 + if #available(iOS 10.0, *) {
  205 + self.saveContext()
  206 + } else {
  207 + // Fallback on earlier versions
  208 + }
205 } 209 }
206 210
207 // MARK: - Core Data stack 211 // MARK: - Core Data stack
208 212
  213 + @available(iOS 10.0, *)
209 lazy var persistentContainer: NSPersistentContainer = { 214 lazy var persistentContainer: NSPersistentContainer = {
210 /* 215 /*
211 The persistent container for the application. This implementation 216 The persistent container for the application. This implementation
@@ -232,9 +237,47 @@ class AppDelegate: UIResponder, UIApplicationDelegate { @@ -232,9 +237,47 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
232 }) 237 })
233 return container 238 return container
234 }() 239 }()
235 - 240 +
  241 + lazy var applicationDocumentsDirectory: URL = {
  242 + let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
  243 + return urls[urls.count-1]
  244 + }()
  245 +
  246 + lazy var managedObjectModel: NSManagedObjectModel = {
  247 + let modelURL = Bundle.main.url(forResource: "ParentAssistant", withExtension: "momd")!
  248 + return NSManagedObjectModel(contentsOf: modelURL)!
  249 + }()
  250 +
  251 + lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
  252 + let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
  253 + let url = self.applicationDocumentsDirectory.appendingPathComponent("ParentAssistant.sqlite")
  254 + var failureReason = "There was an error creating or loading the application's saved data."
  255 + do {
  256 + try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
  257 + } catch {
  258 + // Report any error we got.
  259 + var dict = [String: AnyObject]()
  260 + dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" as AnyObject?
  261 + dict[NSLocalizedFailureReasonErrorKey] = failureReason as AnyObject?
  262 +
  263 + dict[NSUnderlyingErrorKey] = error as NSError
  264 + let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
  265 + NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
  266 + abort()
  267 + }
  268 +
  269 + return coordinator
  270 + }()
  271 +
  272 + lazy var managedObjectContext: NSManagedObjectContext = {
  273 + let coordinator = self.persistentStoreCoordinator
  274 + var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
  275 + managedObjectContext.persistentStoreCoordinator = coordinator
  276 + return managedObjectContext
  277 + }()
236 // MARK: - Core Data Saving support 278 // MARK: - Core Data Saving support
237 279
  280 + @available(iOS 10.0, *)
238 func saveContext () { 281 func saveContext () {
239 let context = persistentContainer.viewContext 282 let context = persistentContainer.viewContext
240 if context.hasChanges { 283 if context.hasChanges {
ParentAssistant/ParentAssistant/Classes/controllers/main/TabBarController.swift
@@ -46,8 +46,12 @@ class TabBarController: UITabBarController { @@ -46,8 +46,12 @@ class TabBarController: UITabBarController {
46 if UIApplication.appVersion() < version{ 46 if UIApplication.appVersion() < version{
47 let alert = UIAlertController(title: "发现新版本", message: dataInformatica["releaseNotes"]! as? String, preferredStyle: .alert) 47 let alert = UIAlertController(title: "发现新版本", message: dataInformatica["releaseNotes"]! as? String, preferredStyle: .alert)
48 alert.addAction(UIAlertAction(title: "前往更新", style: .default, handler: { (action) in 48 alert.addAction(UIAlertAction(title: "前往更新", style: .default, handler: { (action) in
49 - // UIApplication.shared.openURL(URL(string: "itms-apps://itunes.apple.com/app/id1271291794")!)  
50 - UIApplication.shared.open(URL(string: "itms-apps://itunes.apple.com/app/id1357945086")!, options: [:], completionHandler: nil) 49 + if #available(iOS 10.0, *) {
  50 + UIApplication.shared.open(URL(string: "itms-apps://itunes.apple.com/app/id1357945086")!, options: [:], completionHandler: nil)
  51 + } else {
  52 + // Fallback on earlier versions
  53 + UIApplication.shared.openURL(URL(string: "itms-apps://itunes.apple.com/app/id1271291794")!)
  54 + }
51 })) 55 }))
52 alert.addAction(UIAlertAction(title: "以后再说", style: .cancel, handler: { (action) in 56 alert.addAction(UIAlertAction(title: "以后再说", style: .cancel, handler: { (action) in
53 57
ParentAssistant/ParentAssistant/Classes/controllers/my/Model/MessageManager.swift
@@ -12,7 +12,13 @@ extension NSManagedObject { @@ -12,7 +12,13 @@ extension NSManagedObject {
12 12
13 static func creatWith(identifier:String)->NSManagedObject { 13 static func creatWith(identifier:String)->NSManagedObject {
14 //获取管理的数据上下文 对象 14 //获取管理的数据上下文 对象
15 - let context = appDelegate.persistentContainer.viewContext 15 + var context:NSManagedObjectContext!
  16 + if #available(iOS 10.0, *) {
  17 + context = appDelegate.persistentContainer.viewContext
  18 + } else {
  19 + // Fallback on earlier versions
  20 + context = appDelegate.managedObjectContext
  21 + }
16 //创建对象 22 //创建对象
17 let obj = NSEntityDescription.insertNewObject(forEntityName: identifier,into: context) 23 let obj = NSEntityDescription.insertNewObject(forEntityName: identifier,into: context)
18 return obj 24 return obj
@@ -20,7 +26,13 @@ extension NSManagedObject { @@ -20,7 +26,13 @@ extension NSManagedObject {
20 //查询数据操作 26 //查询数据操作
21 static func fetchModel(identifier:String,ownid:String)->[Any]{ 27 static func fetchModel(identifier:String,ownid:String)->[Any]{
22 //获取管理的数据上下文 对象 28 //获取管理的数据上下文 对象
23 - let context = appDelegate.persistentContainer.viewContext 29 + var context:NSManagedObjectContext!
  30 + if #available(iOS 10.0, *) {
  31 + context = appDelegate.persistentContainer.viewContext
  32 + } else {
  33 + // Fallback on earlier versions
  34 + context = appDelegate.managedObjectContext
  35 + }
24 //声明数据的请求 36 //声明数据的请求
25 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier) 37 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier)
26 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] 38 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
@@ -43,7 +55,13 @@ extension NSManagedObject { @@ -43,7 +55,13 @@ extension NSManagedObject {
43 //查询数据操作 55 //查询数据操作
44 static func fetchAllUnReadModel(identifier:String,ownid:String)->[Any]{ 56 static func fetchAllUnReadModel(identifier:String,ownid:String)->[Any]{
45 //获取管理的数据上下文 对象 57 //获取管理的数据上下文 对象
46 - let context = appDelegate.persistentContainer.viewContext 58 + var context:NSManagedObjectContext!
  59 + if #available(iOS 10.0, *) {
  60 + context = appDelegate.persistentContainer.viewContext
  61 + } else {
  62 + // Fallback on earlier versions
  63 + context = appDelegate.managedObjectContext
  64 + }
47 //声明数据的请求 65 //声明数据的请求
48 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier) 66 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier)
49 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)] 67 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
@@ -66,7 +84,13 @@ extension NSManagedObject { @@ -66,7 +84,13 @@ extension NSManagedObject {
66 84
67 func save(){ 85 func save(){
68 //获取管理的数据上下文 对象 86 //获取管理的数据上下文 对象
69 - let context = appDelegate.persistentContainer.viewContext 87 + var context:NSManagedObjectContext!
  88 + if #available(iOS 10.0, *) {
  89 + context = appDelegate.persistentContainer.viewContext
  90 + } else {
  91 + // Fallback on earlier versions
  92 + context = appDelegate.managedObjectContext
  93 + }
70 //保存 94 //保存
71 do { 95 do {
72 try context.save() 96 try context.save()
@@ -77,7 +101,13 @@ extension NSManagedObject { @@ -77,7 +101,13 @@ extension NSManagedObject {
77 } 101 }
78 func delete(){ 102 func delete(){
79 //获取管理的数据上下文 对象 103 //获取管理的数据上下文 对象
80 - let context = appDelegate.persistentContainer.viewContext 104 + var context:NSManagedObjectContext!
  105 + if #available(iOS 10.0, *) {
  106 + context = appDelegate.persistentContainer.viewContext
  107 + } else {
  108 + // Fallback on earlier versions
  109 + context = appDelegate.managedObjectContext
  110 + }
81 context.delete(self) 111 context.delete(self)
82 //重新保存-更新到数据库 112 //重新保存-更新到数据库
83 save() 113 save()