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 1273 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1274 1274 );
1275 1275 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1276   - IPHONEOS_DEPLOYMENT_TARGET = 10.0;
  1276 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1277 1277 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1278 1278 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1279 1279 PRODUCT_NAME = "$(TARGET_NAME)";
... ... @@ -1303,7 +1303,7 @@
1303 1303 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1304 1304 );
1305 1305 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1306   - IPHONEOS_DEPLOYMENT_TARGET = 10.0;
  1306 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1307 1307 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1308 1308 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1309 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 201 func applicationWillTerminate(_ application: UIApplication) {
202 202 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
203 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 211 // MARK: - Core Data stack
208 212  
  213 + @available(iOS 10.0, *)
209 214 lazy var persistentContainer: NSPersistentContainer = {
210 215 /*
211 216 The persistent container for the application. This implementation
... ... @@ -232,9 +237,47 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
232 237 })
233 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 278 // MARK: - Core Data Saving support
237 279  
  280 + @available(iOS 10.0, *)
238 281 func saveContext () {
239 282 let context = persistentContainer.viewContext
240 283 if context.hasChanges {
... ...
ParentAssistant/ParentAssistant/Classes/controllers/main/TabBarController.swift
... ... @@ -46,8 +46,12 @@ class TabBarController: UITabBarController {
46 46 if UIApplication.appVersion() < version{
47 47 let alert = UIAlertController(title: "发现新版本", message: dataInformatica["releaseNotes"]! as? String, preferredStyle: .alert)
48 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 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 12  
13 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 23 let obj = NSEntityDescription.insertNewObject(forEntityName: identifier,into: context)
18 24 return obj
... ... @@ -20,7 +26,13 @@ extension NSManagedObject {
20 26 //查询数据操作
21 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 37 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier)
26 38 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
... ... @@ -43,7 +55,13 @@ extension NSManagedObject {
43 55 //查询数据操作
44 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 66 let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName:identifier)
49 67 fetchRequest.sortDescriptors = [NSSortDescriptor(key: "date", ascending: false)]
... ... @@ -66,7 +84,13 @@ extension NSManagedObject {
66 84  
67 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 95 do {
72 96 try context.save()
... ... @@ -77,7 +101,13 @@ extension NSManagedObject {
77 101 }
78 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 111 context.delete(self)
82 112 //重新保存-更新到数据库
83 113 save()
... ...