Skip to content

Commit f4ee1b9

Browse files
authored
ParseInstallation no longer requires dispatching to main queue (#114)
* ParseInstallation no longer requires dispatching to main queue * nits * Use Keychain thread * Switch back to dispatch queue for tests
1 parent 3852a93 commit f4ee1b9

File tree

13 files changed

+1360
-1587
lines changed

13 files changed

+1360
-1587
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.6...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.3.0...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 1.3.0
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.6...1.3.0)
9+
10+
__Improvements__
11+
- (Breaking Change) No longer require dispatch to main queue when using ParseInstallation. The side effect of this is bade is no longer retrieved by the SDK. The developer should retrieve the badge count on their own and save it to `ParseInstallation` if they require badge ([#114](https://github.com/parse-community/Parse-Swift/pull/114)), thanks to [Corey Baker](https://github.com/cbaker6).
12+
713
### 1.2.6
814
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.5...1.2.6)
915

ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,19 @@ struct Installation: ParseInstallation {
3737
var customKey: String?
3838
}
3939

40-
//: WARNING: All calls on Installation need to be done on the main queue
41-
DispatchQueue.main.async {
42-
43-
/*: Save your first `customKey` value to your `ParseInstallation`.
44-
Performs work on background queue and returns to designated on
45-
designated callbackQueue. If no callbackQueue is specified it
46-
returns to main queue.
47-
*/
48-
Installation.current?.customKey = "myCustomInstallationKey2"
49-
Installation.current?.save { results in
50-
51-
switch results {
52-
case .success(let updatedInstallation):
53-
print("Successfully save myCustomInstallationKey to ParseServer: \(updatedInstallation)")
54-
case .failure(let error):
55-
print("Failed to update installation: \(error)")
56-
}
40+
/*: Save your first `customKey` value to your `ParseInstallation`.
41+
Performs work on background queue and returns to designated on
42+
designated callbackQueue. If no callbackQueue is specified it
43+
returns to main queue.
44+
*/
45+
Installation.current?.customKey = "myCustomInstallationKey2"
46+
Installation.current?.save { results in
47+
48+
switch results {
49+
case .success(let updatedInstallation):
50+
print("Successfully save myCustomInstallationKey to ParseServer: \(updatedInstallation)")
51+
case .failure(let error):
52+
print("Failed to update installation: \(error)")
5753
}
5854
}
5955

ParseSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.2.6"
3+
s.version = "1.3.0"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@
23212321
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23222322
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23232323
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2324-
MARKETING_VERSION = 1.2.6;
2324+
MARKETING_VERSION = 1.3.0;
23252325
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23262326
PRODUCT_NAME = ParseSwift;
23272327
SKIP_INSTALL = YES;
@@ -2345,7 +2345,7 @@
23452345
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23462346
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23472347
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2348-
MARKETING_VERSION = 1.2.6;
2348+
MARKETING_VERSION = 1.3.0;
23492349
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23502350
PRODUCT_NAME = ParseSwift;
23512351
SKIP_INSTALL = YES;
@@ -2411,7 +2411,7 @@
24112411
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24122412
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24132413
MACOSX_DEPLOYMENT_TARGET = 10.13;
2414-
MARKETING_VERSION = 1.2.6;
2414+
MARKETING_VERSION = 1.3.0;
24152415
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24162416
PRODUCT_NAME = ParseSwift;
24172417
SDKROOT = macosx;
@@ -2437,7 +2437,7 @@
24372437
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24382438
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24392439
MACOSX_DEPLOYMENT_TARGET = 10.13;
2440-
MARKETING_VERSION = 1.2.6;
2440+
MARKETING_VERSION = 1.3.0;
24412441
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24422442
PRODUCT_NAME = ParseSwift;
24432443
SDKROOT = macosx;
@@ -2584,7 +2584,7 @@
25842584
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
25852585
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
25862586
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2587-
MARKETING_VERSION = 1.2.6;
2587+
MARKETING_VERSION = 1.3.0;
25882588
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
25892589
MTL_FAST_MATH = YES;
25902590
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
@@ -2613,7 +2613,7 @@
26132613
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
26142614
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26152615
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2616-
MARKETING_VERSION = 1.2.6;
2616+
MARKETING_VERSION = 1.3.0;
26172617
MTL_FAST_MATH = YES;
26182618
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
26192619
PRODUCT_NAME = ParseSwift;
@@ -2640,7 +2640,7 @@
26402640
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26412641
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26422642
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2643-
MARKETING_VERSION = 1.2.6;
2643+
MARKETING_VERSION = 1.3.0;
26442644
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
26452645
MTL_FAST_MATH = YES;
26462646
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
@@ -2668,7 +2668,7 @@
26682668
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26692669
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26702670
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2671-
MARKETING_VERSION = 1.2.6;
2671+
MARKETING_VERSION = 1.3.0;
26722672
MTL_FAST_MATH = YES;
26732673
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
26742674
PRODUCT_NAME = ParseSwift;

Scripts/jazzy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bundle exec jazzy \
55
--author_url http://parseplatform.org \
66
--github_url https://github.com/parse-community/Parse-Swift \
77
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.2.6 \
8+
--module-version 1.3.0 \
99
--theme fullwidth \
1010
--skip-undocumented \
1111
--output ./docs/api \

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
import Foundation
1010

11-
#if canImport(UIKit)
12-
import UIKit
13-
#elseif canImport(AppKit)
14-
import AppKit
15-
#endif
16-
1711
/**
1812
Objects that conform to the `ParseInstallation` protocol have a local representation of an
1913
installation persisted to the Parse cloud. This protocol inherits from the
@@ -23,17 +17,18 @@ import AppKit
2317

2418
A valid `ParseInstallation` can only be instantiated via
2519
*current* because the required identifier fields
26-
are readonly. The `timeZone` and `badge` fields are also readonly properties which
27-
are automatically updated to match the device's time zone and application badge
20+
are readonly. The `timeZone` is also a readonly property which
21+
is automatically updated to match the device's time zone
2822
when the `ParseInstallation` is saved, thus these fields might not reflect the
2923
latest device state if the installation has not recently been saved.
3024

3125
`ParseInstallation`s which have a valid `deviceToken` and are saved to
3226
the Parse Server can be used to target push notifications. Use `setDeviceToken` to set the
3327
`deviceToken` properly.
3428

35-
- warning: Only use `ParseInstallation.current` installations on the main thread as they
36-
require UIApplication for `badge`
29+
- warning: If the use of badge is desired, it should be retrieved by using UIKit, AppKit, etc. and
30+
stored in `ParseInstallation.badge` before saving/updating the installation.
31+
3732
- warning: Linux developers should set `appName`, `appIdentifier`, and `appVersion`
3833
manually as `ParseSwift` doesn't have access to Bundle.main.
3934
*/
@@ -188,9 +183,7 @@ extension ParseInstallation {
188183
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
189184
#endif
190185
//Prepare new installation
191-
DispatchQueue.main.async {
192-
_ = BaseParseInstallation()
193-
}
186+
_ = BaseParseInstallation()
194187
}
195188

196189
/**
@@ -200,7 +193,6 @@ extension ParseInstallation {
200193
*/
201194
public static var current: Self? {
202195
get {
203-
Self.currentInstallationContainer.currentInstallation?.updateBadgeFromDevice()
204196
return Self.currentInstallationContainer.currentInstallation
205197
}
206198
set {
@@ -215,7 +207,6 @@ extension ParseInstallation {
215207
mutating func updateAutomaticInfo() {
216208
updateDeviceTypeFromDevice()
217209
updateTimeZoneFromDevice()
218-
updateBadgeFromDevice()
219210
updateVersionInfoFromDevice()
220211
updateLocaleIdentifierFromDevice()
221212
}
@@ -239,29 +230,6 @@ extension ParseInstallation {
239230
}
240231
}
241232

242-
mutating func updateBadgeFromDevice() {
243-
let applicationBadge: Int!
244-
245-
#if canImport(UIKit) && !os(watchOS)
246-
applicationBadge = UIApplication.shared.applicationIconBadgeNumber
247-
#elseif canImport(AppKit)
248-
guard let currentApplicationBadge = NSApplication.shared.dockTile.badgeLabel else {
249-
//If badgeLabel not set, assume it's 0
250-
applicationBadge = 0
251-
return
252-
}
253-
applicationBadge = Int(currentApplicationBadge)
254-
#else
255-
applicationBadge = 0
256-
#endif
257-
258-
if badge != applicationBadge {
259-
badge = applicationBadge
260-
//Since this changes, update the Keychain whenever it changes
261-
Self.saveCurrentContainerToKeychain()
262-
}
263-
}
264-
265233
mutating func updateVersionInfoFromDevice() {
266234
guard let appInfo = Bundle.main.infoDictionary else {
267235
return

Sources/ParseSwift/Parse.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public struct ParseSwift {
6666
ParseStorage.shared.use(keyValueStore ?? InMemoryKeyValueStore())
6767
ParseConfiguration.sessionDelegate = ParseURLSessionDelegate(callbackQueue: .main, authentication: authentication)
6868
//Prepare installation
69-
DispatchQueue.main.async {
70-
_ = BaseParseInstallation()
71-
}
69+
_ = BaseParseInstallation()
7270
}
7371

7472
internal static func initialize(applicationId: String,

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
enum ParseConstants {
12-
static let parseVersion = "1.2.6"
12+
static let parseVersion = "1.3.0"
1313
static let hashingKey = "parseSwift"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"

Sources/ParseSwift/Storage/KeychainStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func getKeychainQueryTemplate(forService service: String) -> [String: String] {
2929
first device unlock and are not backed up.
3030
*/
3131
struct KeychainStore: SecureStorage {
32-
private let synchronizationQueue: DispatchQueue
32+
let synchronizationQueue: DispatchQueue
3333
private let keychainQueryTemplate: [String: String]
3434

3535
public static var shared = KeychainStore(service: "shared")

0 commit comments

Comments
 (0)