From ca3ed9bd99ea5527f34d6332fcb3f151294122c7 Mon Sep 17 00:00:00 2001
From: Knut Inge Grosland <”hei@knutinge.com”>
Date: Mon, 25 May 2015 22:55:46 +0100
Subject: [PATCH] core data
---
App Reviews.xcodeproj/project.pbxproj | 25 +++++++++++---
AppReviews/AppDelegate.swift | 2 ++
AppReviews/AppReviews.entitlements | 21 +-----------
ReviewManager/ApplicationUpdater.swift | 8 -----
ReviewManager/Models/Application.swift | 2 +-
ReviewManager/PersistentStack.swift | 47 +-------------------------
ReviewManager/ReviewManager.swift | 20 ++++++++---
7 files changed, 40 insertions(+), 85 deletions(-)
diff --git a/App Reviews.xcodeproj/project.pbxproj b/App Reviews.xcodeproj/project.pbxproj
index 9f35357..4ffaaeb 100644
--- a/App Reviews.xcodeproj/project.pbxproj
+++ b/App Reviews.xcodeproj/project.pbxproj
@@ -395,6 +395,7 @@
49ACB84E1AD5CAA00050C1B7 /* Resources */,
C74A12F1B404CD9A47F25C18 /* Embed Pods Frameworks */,
72B401262D76AFCCD7B98C00 /* Copy Pods Resources */,
+ 49D09E561B134BDF006B39C9 /* Sign Sparkle */,
);
buildRules = (
);
@@ -423,10 +424,10 @@
enabled = 0;
};
com.apple.Sandbox = {
- enabled = 1;
+ enabled = 0;
};
com.apple.iCloud = {
- enabled = 1;
+ enabled = 0;
};
};
};
@@ -523,6 +524,20 @@
shellPath = /bin/sh;
shellScript = "LOCATION=\"${BUILT_PRODUCTS_DIR}\"/\"${FRAMEWORKS_FOLDER_PATH}\"\n\n# Usually set by Xcode\nCODE_SIGN_IDENTITY=\"Developer ID Application: Knut Inge Grosland\"\n\ncodesign --verbose --force --sign \"$CODE_SIGN_IDENTITY\" \"$LOCATION/Sparkle.framework/Versions/A\"";
};
+ 49D09E561B134BDF006B39C9 /* Sign Sparkle */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Sign Sparkle";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "LOCATION=\"${BUILT_PRODUCTS_DIR}\"/\"${FRAMEWORKS_FOLDER_PATH}\"\n\n# Usually set by Xcode\nCODE_SIGN_IDENTITY=\"Developer ID Application: Knut Inge Grosland\"\n\ncodesign --verbose --force --sign \"$CODE_SIGN_IDENTITY\" \"$LOCATION/Sparkle.framework/Versions/A\"";
+ };
72B401262D76AFCCD7B98C00 /* Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -758,8 +773,7 @@
baseConfigurationReference = 8E9E3A98AF3DC476EF9A0809 /* Pods.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
- CODE_SIGN_ENTITLEMENTS = AppReviews/AppReviews.entitlements;
- CODE_SIGN_IDENTITY = "Developer ID Application";
+ CODE_SIGN_IDENTITY = "Mac Developer: Knut Inge Grosland (BV7ZH22G55)";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer: Knut Inge Grosland (BV7ZH22G55)";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = AppReviews/Info.plist;
@@ -777,7 +791,6 @@
baseConfigurationReference = F9CE0DF35CA051BD774393CD /* Pods.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
- CODE_SIGN_ENTITLEMENTS = AppReviews/AppReviews.entitlements;
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application: Knut Inge Grosland (2PRW676NCQ)";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application: Knut Inge Grosland (2PRW676NCQ)";
COMBINE_HIDPI_IMAGES = YES;
@@ -808,6 +821,7 @@
INFOPLIST_FILE = AppReviewsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "App ReviewsTests";
+ PROVISIONING_PROFILE = "";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/App Reviews.app/Contents/MacOS/App Reviews";
};
name = Debug;
@@ -827,6 +841,7 @@
INFOPLIST_FILE = AppReviewsTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "App ReviewsTests";
+ PROVISIONING_PROFILE = "";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/App Reviews.app/Contents/MacOS/App Reviews";
};
name = Release;
diff --git a/AppReviews/AppDelegate.swift b/AppReviews/AppDelegate.swift
index 21fef9a..822e383 100644
--- a/AppReviews/AppDelegate.swift
+++ b/AppReviews/AppDelegate.swift
@@ -23,6 +23,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: Application Process
func applicationDidFinishLaunching(aNotification: NSNotification) {
+
+ // UA-62792522-4
// Create ReviewManager shared object
var manager = ReviewManager.start()
diff --git a/AppReviews/AppReviews.entitlements b/AppReviews/AppReviews.entitlements
index 68af6aa..0c67376 100644
--- a/AppReviews/AppReviews.entitlements
+++ b/AppReviews/AppReviews.entitlements
@@ -1,24 +1,5 @@
-
- com.apple.developer.icloud-container-identifiers
-
- iCloud.$(CFBundleIdentifier)
-
- com.apple.developer.icloud-services
-
- CloudDocuments
-
- com.apple.developer.ubiquity-container-identifiers
-
- iCloud.$(CFBundleIdentifier)
-
- com.apple.security.app-sandbox
-
- com.apple.security.network.client
-
- com.apple.security.network.server
-
-
+
diff --git a/ReviewManager/ApplicationUpdater.swift b/ReviewManager/ApplicationUpdater.swift
index 9fbae2d..d72978d 100644
--- a/ReviewManager/ApplicationUpdater.swift
+++ b/ReviewManager/ApplicationUpdater.swift
@@ -25,14 +25,6 @@ class ApplicationUpdater {
init() {
-// let persistenceStoreWillChhange = NSNotificationCenter.defaultCenter().addObserverForName(NSPersistentStoreCoordinatorStoresWillChangeNotification, object: nil, queue: nil) { [weak self] notification in
-// self?.applications .removeAll(keepCapacity: true)
-// }
-//
-// let persistenceStoreDidChange = NSNotificationCenter.defaultCenter().addObserverForName(NSPersistentStoreCoordinatorStoresDidChangeNotification, object: nil, queue: nil) { [weak self] notification in
-// self?.updateMonitoredApplications()
-// }
-
let applicationMonitor = NSNotificationCenter.defaultCenter().addObserverForName(kDidUpdateApplicationNotification, object: nil, queue: nil) { [weak self] notification in
self?.updateMonitoredApplications()
}
diff --git a/ReviewManager/Models/Application.swift b/ReviewManager/Models/Application.swift
index ebd8a59..2fb7685 100644
--- a/ReviewManager/Models/Application.swift
+++ b/ReviewManager/Models/Application.swift
@@ -185,5 +185,5 @@ extension JSON {
var averageUserRating: NSNumber { return NSNumber(float:(self["averageUserRating"].stringValue as NSString).floatValue) }
var userRatingCount: NSNumber { return NSNumber(integer: self["userRatingCount"].stringValue.toInt() ?? 0) }
- var isApplicationEntity: Bool{ return self.trackId != nil }
+ var isApplicationEntity: Bool{ return trackId != nil }
}
diff --git a/ReviewManager/PersistentStack.swift b/ReviewManager/PersistentStack.swift
index 019d591..84f05b8 100644
--- a/ReviewManager/PersistentStack.swift
+++ b/ReviewManager/PersistentStack.swift
@@ -16,12 +16,9 @@ let kDidUpdateReviewsNotification = "kDidUpdateReviewsNotification"
class PersistentStack {
- private var iCloudSync = true
-
var managedObjectContext: NSManagedObjectContext!
var modelURL: NSURL
var storeURL: NSURL
- var persistenceStoreWillChange = false
init(storeURL: NSURL, modelURL: NSURL) {
self.modelURL = modelURL
@@ -34,51 +31,16 @@ class PersistentStack {
managedObjectContext = setupManagedObjectContextWithConcurrencyType(.MainQueueConcurrencyType)
managedObjectContext.undoManager = NSUndoManager()
- if iCloudSync {
- addNotficationsForPersistentStack()
- }
-
let managedObjectDidSave = NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextDidSaveNotification, object: nil, queue: nil) { [weak self] notification in
self?.managedObjectDidSave(notification)
}
}
- func addNotficationsForPersistentStack() {
- let persistenceStoreDidImport = NSNotificationCenter.defaultCenter().addObserverForName(NSPersistentStoreDidImportUbiquitousContentChangesNotification, object: nil, queue: nil) { [weak self] notification in
- self?.managedObjectDidSave(notification)
- }
-
- let persistenceStoreDidChange = NSNotificationCenter.defaultCenter().addObserverForName(NSPersistentStoreCoordinatorStoresDidChangeNotification, object: nil, queue: nil) { [weak self] notification in
- self?.persistenceStoreWillChange = false
- }
-
- let persistenceStoreWillChangeNot = NSNotificationCenter.defaultCenter().addObserverForName(NSPersistentStoreCoordinatorStoresWillChangeNotification, object: nil, queue: NSOperationQueue.mainQueue()) { [weak self] notification in
- self?.managedObjectContext.performBlock({ () -> Void in
-
- if (self?.managedObjectContext.hasChanges != nil) {
- var error: NSError?
- self?.managedObjectContext.save(&error)
-
- } else {
- // drop any managed object references
- self?.persistenceStoreWillChange = true
- self?.managedObjectContext.reset()
- }
- })
- }
-
-
- }
-
func managedObjectDidSave(notification: NSNotification) {
let moc = managedObjectContext;
if notification.object as? NSManagedObjectContext != moc {
moc.performBlock({ () -> Void in
- if (self.persistenceStoreWillChange) {
- return
- }
-
self.mergeChangesFromSaveNotification(notification, intoContext: moc)
var newReviews = Set()
@@ -165,17 +127,10 @@ class PersistentStack {
let managedObjectContext = NSManagedObjectContext(concurrencyType: concurrencyType)
- var storeOptions: [NSObject: AnyObject]?
-
- // Enable iCloudSync
- if (iCloudSync) {
- storeOptions = [NSPersistentStoreUbiquitousContentNameKey: "AppReviews"]
- }
-
if let managedObjectModel = managedObjectModel() {
managedObjectContext.persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: managedObjectModel)
var error: NSError?
- managedObjectContext.persistentStoreCoordinator?.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: storeOptions, error: &error)
+ managedObjectContext.persistentStoreCoordinator?.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error)
if error != nil {
println(error)
println(storeURL.path)
diff --git a/ReviewManager/ReviewManager.swift b/ReviewManager/ReviewManager.swift
index dbc1e40..557869e 100644
--- a/ReviewManager/ReviewManager.swift
+++ b/ReviewManager/ReviewManager.swift
@@ -65,15 +65,25 @@ final class ReviewManager {
}
func storeURL() -> NSURL {
- let appName = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String ?? "AppReviews"
+ let appName = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String ?? "App Reviews"
var error: NSError? = nil
- let applicationSupportDirectory = NSFileManager.defaultManager().URLForDirectory(.ApplicationSupportDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true, error: &error)
- let appdirectory = applicationSupportDirectory?.URLByAppendingPathComponent(appName, isDirectory: true)
- let url = appdirectory?.URLByAppendingPathComponent(kSQLiteFileName)
+ // ApplicationSupportDirectory
+
+ let applicationSupportDirectory = NSFileManager.defaultManager().URLForDirectory(.DesktopDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true, error: &error)
+ let appDirectory = applicationSupportDirectory?.URLByAppendingPathComponent(appName, isDirectory: true)
+
+ let success = NSFileManager.defaultManager().createDirectoryAtPath(appDirectory!.URLString, withIntermediateDirectories: true, attributes: nil, error: &error)
+
if error != nil {
- println("error storeURL: \(error?.localizedDescription)")
+ println("createDirectoryAtPath: \(error?.localizedDescription)")
}
+ let url = appDirectory?.URLByAppendingPathComponent(kSQLiteFileName)
+
+ if error != nil {
+ println("error storeURL: \(error?.localizedDescription)")
+ }
+
return url!
}