Commit 9ff9fa456e1b5ad556c6deca32de5c5491eafad0

Authored by Cao yang
2 parents d572a428 aad3af55
Exists in parentassistant

Merge branch 'parentassistant' of http://git.shunzhi.net/iosgroup/parentassistan…

…t into parentassistant
ParentAssistant/ParentAssistant.xcodeproj/project.pbxproj
... ... @@ -289,6 +289,7 @@
289 289 BF7A4C82204E338400460463 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
290 290 BF7A4C83204E338400460463 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
291 291 BFA74439207DB6EE00845D30 /* ActivationSchoolCardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivationSchoolCardViewController.swift; sourceTree = "<group>"; };
  292 + BFA7443B2080869D00845D30 /* ParentAssistant 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "ParentAssistant 2.xcdatamodel"; sourceTree = "<group>"; };
292 293 BFBC06BB2063AE8800CCFAFF /* ZLaunchAd.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLaunchAd.swift; sourceTree = "<group>"; };
293 294 BFBC06BC2063AE8800CCFAFF /* ZLaunchAdAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLaunchAdAnimation.swift; sourceTree = "<group>"; };
294 295 BFBC06BD2063AE8800CCFAFF /* ZLaunchAdButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLaunchAdButton.swift; sourceTree = "<group>"; };
... ... @@ -1284,7 +1285,7 @@
1284 1285 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1285 1286 );
1286 1287 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1287   - IPHONEOS_DEPLOYMENT_TARGET = 10.0;
  1288 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1288 1289 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1289 1290 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1290 1291 PRODUCT_NAME = "$(TARGET_NAME)";
... ... @@ -1314,7 +1315,7 @@
1314 1315 "$(PROJECT_DIR)/Pods/NIMSDK_LITE/NIMSDK",
1315 1316 );
1316 1317 INFOPLIST_FILE = "$(SRCROOT)/ParentAssistant/Supporting Files/Info.plist";
1317   - IPHONEOS_DEPLOYMENT_TARGET = 10.0;
  1318 + IPHONEOS_DEPLOYMENT_TARGET = 9.0;
1318 1319 LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1319 1320 PRODUCT_BUNDLE_IDENTIFIER = net.shunzi.app.ParentAssistant;
1320 1321 PRODUCT_NAME = "$(TARGET_NAME)";
... ... @@ -1395,9 +1396,10 @@
1395 1396 BF7A4C3A204CD55300460463 /* ParentAssistant.xcdatamodeld */ = {
1396 1397 isa = XCVersionGroup;
1397 1398 children = (
  1399 + BFA7443B2080869D00845D30 /* ParentAssistant 2.xcdatamodel */,
1398 1400 BF7A4C3B204CD55300460463 /* ParentAssistant.xcdatamodel */,
1399 1401 );
1400   - currentVersion = BF7A4C3B204CD55300460463 /* ParentAssistant.xcdatamodel */;
  1402 + currentVersion = BFA7443B2080869D00845D30 /* ParentAssistant 2.xcdatamodel */;
1401 1403 path = ParentAssistant.xcdatamodeld;
1402 1404 sourceTree = "<group>";
1403 1405 versionGroupType = wrapper.xcdatamodel;
... ...
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()
... ...
ParentAssistant/ParentAssistant/NIM/YXMessageManager.swift
... ... @@ -113,6 +113,7 @@ class YXMessageManager: NSObject,NIMLoginManagerDelegate,NIMSystemNotificationMa
113 113 }else if info["type"].stringValue=="ordermess"{//订购通知
114 114 let attachItem = NSManagedObject.creatWith(identifier: "Message") as! Message
115 115 attachItem.date=Date(timeIntervalSince1970: notification.timestamp)
  116 + attachItem.type = "ordermess"
116 117 attachItem.content = info["content"].stringValue
117 118 attachItem.ownId = AccountManager.shared.userid
118 119 attachItem.save()
... ...
ParentAssistant/ParentAssistant/ParentAssistant.xcdatamodeld/.xccurrentversion
... ... @@ -3,6 +3,6 @@
3 3 <plist version="1.0">
4 4 <dict>
5 5 <key>_XCCurrentVersionName</key>
6   - <string>ParentAssistant.xcdatamodel</string>
  6 + <string>ParentAssistant 2.xcdatamodel</string>
7 7 </dict>
8 8 </plist>
... ...
ParentAssistant/ParentAssistant/ParentAssistant.xcdatamodeld/ParentAssistant 2.xcdatamodel/contents 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2 +<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="13772" systemVersion="16G29" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
  3 + <entity name="Message" representedClassName="Message" syncable="YES" codeGenerationType="class">
  4 + <attribute name="content" optional="YES" attributeType="String" syncable="YES"/>
  5 + <attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
  6 + <attribute name="isReaded" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES" syncable="YES"/>
  7 + <attribute name="ownId" optional="YES" attributeType="String" syncable="YES"/>
  8 + <attribute name="type" optional="YES" attributeType="String" syncable="YES"/>
  9 + </entity>
  10 + <elements>
  11 + <element name="Message" positionX="-63" positionY="-18" width="128" height="120"/>
  12 + </elements>
  13 +</model>
0 14 \ No newline at end of file
... ...