88
99import 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
0 commit comments