From dcaa706feb8c39b540f86e31e8cbb645dcce6f7c Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 12 Aug 2015 12:28:22 +0800 Subject: [PATCH 1/3] enable App Group "group.Catch-Inc.Yep" --- Yep.xcodeproj/project.pbxproj | 11 +++++++++++ Yep/Yep.entitlements | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 Yep/Yep.entitlements diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index f8db1cf3..342ae276 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -461,6 +461,7 @@ 845E1A651B788EF3001E0789 /* EditSkillsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EditSkillsViewController.swift; path = ViewControllers/EditSkills/EditSkillsViewController.swift; sourceTree = ""; }; 848806AE1B789A2D000C5424 /* EditSkillCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EditSkillCell.swift; path = Views/Cells/EditSkill/EditSkillCell.swift; sourceTree = ""; }; 848806AF1B789A2D000C5424 /* EditSkillCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditSkillCell.xib; path = Views/Cells/EditSkill/EditSkillCell.xib; sourceTree = ""; }; + 848806B21B7B0230000C5424 /* Yep.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Yep.entitlements; sourceTree = ""; }; 84C959881B731FD20017D3ED /* ChatBaseCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChatBaseCell.swift; path = Views/Cells/ChatBaseCell/ChatBaseCell.swift; sourceTree = ""; }; 88C96122C478C4D134F634F6 /* Pods-Yep.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Yep.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Yep/Pods-Yep.debug.xcconfig"; sourceTree = ""; }; C3146F0F60F2A38BC6E0FA66 /* Pods_Yep.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Yep.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -563,6 +564,7 @@ 0A8F54AD1AB67D11004AD60E /* Yep */ = { isa = PBXGroup; children = ( + 848806B21B7B0230000C5424 /* Yep.entitlements */, 0A8F54B01AB67D11004AD60E /* AppDelegate.swift */, 0AD7EA581AC3EAF300617758 /* Yep-Bridging-Header.h */, 50E114F51ABBF9D100F13000 /* Realm */, @@ -1644,6 +1646,9 @@ CreatedOnToolsVersion = 6.3; DevelopmentTeam = TKRALRXCKN; SystemCapabilities = { + com.apple.ApplicationGroups.iOS = { + enabled = 1; + }; com.apple.BackgroundModes = { enabled = 1; }; @@ -2094,7 +2099,9 @@ baseConfigurationReference = 88C96122C478C4D134F634F6 /* Pods-Yep.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = Yep/Yep.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2112,6 +2119,7 @@ "$(PROJECT_DIR)/Yep/JPush", ); PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SWIFT_OBJC_BRIDGING_HEADER = "Yep/Yep-Bridging-Header.h"; }; name = Debug; @@ -2121,7 +2129,9 @@ baseConfigurationReference = 4EEAF88E6C6D61E595249DF5 /* Pods-Yep.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = Yep/Yep.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -2139,6 +2149,7 @@ "$(PROJECT_DIR)/Yep/JPush", ); PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SWIFT_OBJC_BRIDGING_HEADER = "Yep/Yep-Bridging-Header.h"; }; name = Release; diff --git a/Yep/Yep.entitlements b/Yep/Yep.entitlements new file mode 100644 index 00000000..8ac3c5c2 --- /dev/null +++ b/Yep/Yep.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.Catch-Inc.Yep + + + From 8ff3f19bc1dc2b0e2194b5be947b2a85e15f0ce6 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 12 Aug 2015 12:38:37 +0800 Subject: [PATCH 2/3] put Realm in App Group --- Yep/AppDelegate.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index ca3b60cb..e3273d4a 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -23,6 +23,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + // 默认将 Realm 放在 App Group 里 + + let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.Catch-Inc.Yep")! + let realmPath = directory.path!.stringByAppendingPathComponent("db.realm") + Realm.defaultPath = realmPath + + // Realm 版本迁移 + setSchemaVersion(15, Realm.defaultPath, { migration, oldSchemaVersion in // We haven’t migrated anything yet, so oldSchemaVersion == 0 if oldSchemaVersion < 1 { From 00377f6a46bbe1d469844251899de6dcf77dcb55 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 12 Aug 2015 12:48:53 +0800 Subject: [PATCH 3/3] put YepUserDefaults in App Group --- Yep/AppDelegate.swift | 2 +- Yep/Configs/YepConfig.swift | 2 ++ Yep/Helpers/YepUserDefaults.swift | 12 ++---------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index e3273d4a..37f8ef93 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // 默认将 Realm 放在 App Group 里 - let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.Catch-Inc.Yep")! + let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(YepConfig.appGroupID)! let realmPath = directory.path!.stringByAppendingPathComponent("db.realm") Realm.defaultPath = realmPath diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index fc2773a6..5b98a489 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -10,6 +10,8 @@ import UIKit import Ruler class YepConfig { + + static let appGroupID: String = "group.Catch-Inc.Yep" static let minMessageTextLabelWidth: CGFloat = 20.0 diff --git a/Yep/Helpers/YepUserDefaults.swift b/Yep/Helpers/YepUserDefaults.swift index 041473ce..5b7e0f52 100644 --- a/Yep/Helpers/YepUserDefaults.swift +++ b/Yep/Helpers/YepUserDefaults.swift @@ -80,10 +80,11 @@ class Listenable { class YepUserDefaults { + static let defaults = NSUserDefaults(suiteName: YepConfig.appGroupID)! + // MARK: ReLogin class func cleanAllUserDefaults() { - let defaults = NSUserDefaults.standardUserDefaults() defaults.removeObjectForKey(v1AccessTokenKey) defaults.removeObjectForKey(userIDKey) @@ -117,7 +118,6 @@ class YepUserDefaults { } static var v1AccessToken: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let v1AccessToken = defaults.stringForKey(v1AccessTokenKey) return Listenable(v1AccessToken) { v1AccessToken in @@ -134,7 +134,6 @@ class YepUserDefaults { }() static var userID: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let userID = defaults.stringForKey(userIDKey) return Listenable(userID) { userID in @@ -143,7 +142,6 @@ class YepUserDefaults { }() static var nickname: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let nickname = defaults.stringForKey(nicknameKey) return Listenable(nickname) { nickname in @@ -163,7 +161,6 @@ class YepUserDefaults { }() static var introduction: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let introduction = defaults.stringForKey(introductionKey) return Listenable(introduction) { introduction in @@ -183,7 +180,6 @@ class YepUserDefaults { }() static var avatarURLString: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let avatarURLString = defaults.stringForKey(avatarURLStringKey) return Listenable(avatarURLString) { avatarURLString in @@ -204,7 +200,6 @@ class YepUserDefaults { }() static var badge: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let badge = defaults.stringForKey(badgeKey) return Listenable(badge) { badge in @@ -224,7 +219,6 @@ class YepUserDefaults { }() static var pusherID: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let pusherID = defaults.stringForKey(pusherIDKey) return Listenable(pusherID) { pusherID in @@ -246,7 +240,6 @@ class YepUserDefaults { }() static var areaCode: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let areaCode = defaults.stringForKey(areaCodeKey) return Listenable(areaCode) { areaCode in @@ -255,7 +248,6 @@ class YepUserDefaults { }() static var mobile: Listenable = { - let defaults = NSUserDefaults.standardUserDefaults() let mobile = defaults.stringForKey(mobileKey) return Listenable(mobile) { mobile in