You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Maybe add 1 day delay to showing update alert: to avoid an issue where Apple updates the JSON faster than the app binary propogates to the App Store. https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/%20Extensions/Date%2BAppVersion.swift
97
97
- Doc params
98
98
- Clean up comments
99
+
- Add support for swiftui
99
100
100
101
## License
101
102
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/UpgradeAlert+Variables.swift
+5
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ extension UpgradeAlert {
6
6
/**
7
7
* Computed property to generate the request URL for app information.
8
8
* It uses the bundle identifier of the current app to create the URL.
9
+
* - Description: This property constructs a URL used to fetch information about the application from the iTunes API based on the application's bundle identifier.
9
10
* - Returns: A URL pointing to the app's information on iTunes.
10
11
* - Note: This URL might need a country code for region-specific apps.
11
12
* - Fixme: ⚠️️ Consider renaming this to appInfoRequestURL for clarity.
@@ -23,6 +24,7 @@ extension UpgradeAlert {
23
24
extensionUpgradeAlert{
24
25
/**
25
26
* Typealias for a function that generates an alert message.
27
+
* - Description: Defines a function type used to generate a custom alert message based on the app's name and version.
26
28
* - Parameters:
27
29
* - appName: The name of the app. This can be nil.
* - Description: Defines a closure used as a completion handler to process the outcome of an update check or alert interaction.
35
38
* - Parameters:
36
39
* - outcome: The outcome of the operation, encapsulated in a UAOutcome object.
37
40
* - Note: This function does not return a value.
@@ -40,6 +43,7 @@ extension UpgradeAlert {
40
43
/**
41
44
* Default completion handler function.
42
45
* This function simply prints the outcome of the operation.
46
+
* - Description: This default completion handler logs the outcome of the operation to the console, providing a simple way to observe the results of the update check or alert interaction.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/UpgradeAlert.swift
+4-1
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ import UIKit
5
5
import Cocoa
6
6
#endif
7
7
/**
8
+
* - Description: The `UpgradeAlert` class is responsible for managing the update notification process within an application. It checks for new versions of the app on the App Store, compares it with the current version, and alerts the user if an update is necessary.
8
9
* - Remark: What if a user doesn't want to update and there is no other option than to update?
9
10
* - Remark: If the app always show popup when getting focus. Then activate flight-mode. Launch the app again.
10
11
* - Remark: Title and message are optional, default values are used if nil etc
@@ -17,6 +18,7 @@ public final class UpgradeAlert {}
17
18
extensionUpgradeAlert{
18
19
/**
19
20
* Check for updates
21
+
* - Description: Initiates a check for new versions of the app available on the App Store. If a newer version is found, it prompts the user with an update alert.
20
22
* - Remark: shows alert with one or two btns
21
23
* - Parameter: withConfirmation You can force the update by calling, Or the user can choose if they want to update now or later by calling
22
24
* - Remark: Version of the app you want to mark for the update. For example, 1.0.0 // This is the version you want the user to force upgrade to a newer version.
@@ -61,6 +63,7 @@ extension UpgradeAlert {
61
63
*/
62
64
extensionUpgradeAlert{
63
65
/**
66
+
* - Description: Retrieves the app information from the App Store using a network request. This function fetches the JSON data from the App Store API and decodes it to `AppInfo` format, handling errors appropriately.
64
67
* let url = URL(string: "http://www.")
65
68
* - Remark: The url will work if the app is available for all markets. but if the app is removed from some countries. the url wont work. language code must be added etc: see: https://medium.com/usemobile/get-app-version-from-app-store-and-more-e43c5055156a
66
69
* - Note: More url and json parsing here: https://github.com/appupgrade-dev/app-upgrade-ios-sdk/blob/main/Sources/AppUpgrade/AppUpgradeApi.swift
@@ -95,13 +98,13 @@ extension UpgradeAlert {
95
98
task.resume()
96
99
}
97
100
}
98
-
99
101
/**
100
102
* Alert
101
103
*/
102
104
extensionUpgradeAlert{
103
105
/**
104
106
* Example code for iOS: mark with os fence
107
+
* - Description: Presents an alert to the user with options based on the app's update requirements. The alert informs the user about the availability of a new version and provides options to update immediately or defer the update.
105
108
* - Remark: For macOS it coud be wise to add some comment regarding setting system-wide autoupdate to avoid future alert popups etc
106
109
* - Remark: Can be used: "itms-apps://itunes.apple.com/app/\(appId)")
* - Description: Determines if the application is a beta version by checking the app store receipt URL for specific substrings that identify simulator or TestFlight environments.
25
34
* - Note: From here: https://stackoverflow.com/a/38984554/5389500
26
35
* - Note: More complex example: https://stackoverflow.com/a/33830605/5389500
27
36
* - Note: Another example: https://stackoverflow.com/a/59047187/5389500
@@ -30,13 +39,17 @@ extension Bundle {
30
39
* - Note: Seems like this can determine if an app is beta: https://developer.apple.com/documentation/appstoreconnectapi/list_all_builds_of_an_app
31
40
* - Fixme: ⚠️️ Here is code that checks if something is testflight: https://gist.github.com/lukaskubanek/cbfcab29c0c93e0e9e0a16ab09586996
32
41
* fix. we could make BundleError enum BundleError: Error { case appStoreReceiptURLNotFound }
42
+
* Example: `let isBeta = Bundle.isBeta`
33
43
*/
34
44
publicstaticvarisBeta:Bool{ // was named: isSimulatorOrTestFlight
45
+
// Retrieves the path of the app store receipt URL, if it exists.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/ext/NSAlert+Ext.swift
+5-9
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ import Cocoa
4
4
extensionNSAlert{
5
5
/**
6
6
* Presents a warning alert to the user with customizable text, buttons, and completion handler.
7
-
*
7
+
* - Description: Displays a modal alert dialog on macOS with customizable titles for the buttons and a completion handler to capture the user's response.
8
8
* ## Examples:
9
9
* NSAlert.present(question: "Ok?", text: "Choose your answer.") { answer in
10
10
* print(answer)
@@ -19,10 +19,10 @@ extension NSAlert {
19
19
* - complete: A closure that is called when the user dismisses the alert. The closure takes a single Boolean parameter that is true if the user clicked the OK button and false otherwise.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/ext/UIAlertController+Ext.swift
+2
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ import UIKit
4
4
extensionUIAlertController{
5
5
/**
6
6
* Present alert
7
+
* - Description: Presents the alert controller modally on the currently active view controller or the root view controller if no other controllers are presented.
7
8
* Fix: throw error if vc is not available?
8
9
*/
9
10
internalfunc present(){
@@ -16,6 +17,7 @@ extension UIAlertController {
16
17
extensionUIAlertController{
17
18
/**
18
19
* Presented or root view-controller
20
+
* - Description: Retrieves the currently presented view controller or the root view controller if no other view controller is presented.
19
21
* - Note: Sometimes there is no vc: https://stackoverflow.com/a/30509569/5389500
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/helper/AppInfo.swift
+4-1
Original file line number
Diff line number
Diff line change
@@ -3,23 +3,26 @@ import Foundation
3
3
/**
4
4
* This struct represents the basic information about an application.
5
5
* It includes the current version of the application and the URL to the application's page on the App Store.
6
-
*
6
+
* - Description: This struct encapsulates essential details about the application, such as its current version and the URL to its App Store page, facilitating easy access to its public listing for update and review purposes.
7
7
* - Remark: More information such as rating, release date, release notes etc. can be fetched. For more details, see: https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/AppStoreVersion.swift
8
8
* - Fixme: ⚠️️ Consider renaming this struct to UAAppInfo for better clarity.
9
9
* - Fixme: ⚠️️ Add more detailed documentation for this struct and its properties.
10
10
*/
11
11
publicstructAppInfo:Decodable{
12
12
/**
13
13
* The current version of the application.
14
+
* - Description: Specifies the version of the application as a string, which is used to determine if an update is needed.
14
15
*/
15
16
publicletversion:String
16
17
/**
17
18
* The URL to the application's page on the App Store.
18
19
* This might be optional for macOS applications as they might not have an App Store page.
20
+
* - Description: Specifies the URL to the application's page on the App Store, which can be used to direct users to update or review the app.
19
21
*/
20
22
publiclettrackViewUrl:String
21
23
/**
22
24
* Initializes a new instance of `AppInfo`.
25
+
* - Description: Initializes a new instance of `AppInfo` with the specified version and App Store URL.
23
26
* - Parameters:
24
27
* - version: The current version of the application.
25
28
* - trackViewUrl: The URL to the application's page on the App Store.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/helper/UAConfig.swift
+8-1
Original file line number
Diff line number
Diff line change
@@ -2,31 +2,37 @@ import Foundation
2
2
/**
3
3
* This struct is used to configure the Upgrade Alert (UA).
4
4
* It contains all the necessary parameters to customize the alert message.
5
+
* - Description: This struct configures the behavior and presentation of upgrade alerts within the application, allowing customization of alert titles, messages, and button labels based on the upgrade requirements.
5
6
*/
6
7
publicstructUAConfig{
7
8
/**
8
9
* Determines whether the upgrade is mandatory or optional.
10
+
* - Description: Indicates if the update is compulsory, requiring immediate action, or if it can be deferred.
9
11
*/
10
12
letisRequired:Bool
11
13
/**
12
14
* The title of the alert.
15
+
* - Description: The title displayed on the upgrade alert, informing the user of the nature of the alert.
13
16
*/
14
17
letalertTitle:String
15
18
/**
16
19
* The message of the alert. It's a function that takes the app name and version as parameters.
20
+
* - Description: Specifies the content of the alert message, dynamically generated based on the application's name and the new version available.
17
21
*/
18
22
letalertMessage:UpgradeAlert.AlertMessage
19
23
/**
20
24
* The title of the button that allows the user to postpone the upgrade.
25
+
* - Description: The title of the button that allows the user to defer the upgrade process, providing an option to initiate it at a later time.
21
26
*/
22
27
letlaterButtonTitle:String
23
28
/**
24
29
* The title of the button that initiates the upgrade.
30
+
* - Description: The title of the button that initiates the upgrade process, prompting the user to immediately download and install the latest version of the application.
25
31
*/
26
32
letupdateButtonTitle:String
27
33
/**
28
34
* Initializes a new UAConfig with the given parameters.
29
-
*
35
+
* - Description: Initializes a new instance of `UAConfig` with specified settings for the upgrade alert.
30
36
* - Parameters:
31
37
* - isRequired: A boolean indicating whether the upgrade is mandatory.
32
38
* - alertTitle: The title of the alert.
@@ -49,6 +55,7 @@ extension UAConfig {
49
55
/**
50
56
* Provides a default configuration for the alert.
51
57
* This can be used when no specific configuration is provided.
58
+
* - Description: Returns a default `UAConfig` instance with predefined values for alert title, message, and button titles, suitable for general use cases where a specific configuration is not necessary.
Copy file name to clipboardexpand all lines: Sources/UpgradeAlert/helper/UAError.swift
+5
Original file line number
Diff line number
Diff line change
@@ -2,24 +2,29 @@ import Foundation
2
2
/**
3
3
* Error type. So we can track if bundle id etc faults.
4
4
* This enum is used to handle errors in a more structured way, allowing for better error handling and debugging.
5
+
* - Description: Enumerates the various errors that can occur within the UpgradeAlert system, providing specific types for different error scenarios to facilitate precise error handling.
5
6
*/
6
7
publicenumUAError:Error{
7
8
/**
8
9
* This error is thrown when the URL for the App Store is invalid.
10
+
* - Description: Occurs when the URL intended to direct to the App Store is malformed or not properly formatted, preventing navigation to the App Store page.
9
11
*/
10
12
case invalidAppStoreURL
11
13
/**
12
14
* This error is thrown when a general URL is invalid.
15
+
* - Description: Occurs when a general URL that is not specifically for the App Store is malformed or not properly formatted, preventing proper URL navigation or usage.
13
16
*/
14
17
case invalideURL
15
18
/**
16
19
* This error is thrown when the response from a request is invalid.
17
20
* - Parameter description: Provides more details about the error.
21
+
* - Description: Provides a detailed explanation of what went wrong with the response, including specifics that can help in debugging the issue.
18
22
*/
19
23
case invalidResponse(description:String)
20
24
/**
21
25
* This error is thrown when there is an issue with the bundle.
22
26
* The desc parameter provides more details about the error.
27
+
* - Description: Indicates an error related to the application's bundle, such as missing required resources or incorrect configuration settings.
* This enum represents the possible outcomes of an upgrade alert.
4
+
* - Description: Enumerates the various outcomes that can occur after presenting an upgrade alert to the user, allowing for a structured response handling based on the user's decision or any error that might occur.
4
5
* - Fixme: ⚠️️ Consider renaming the cases to: notNow, notNeeded, appStoreOpened for better clarity.
5
6
* - Fixme: ⚠️️ Add more detailed documentation for each case.
6
7
*/
7
8
publicenumUAOutcome{
8
9
/**
9
10
* Represents the outcome where the app is up-to-date and no upgrade is needed.
11
+
* - Description: Indicates that the current version of the application is the latest available version, and no update action is required.
10
12
*/
11
13
case updateNotNeeded
12
14
/**
13
15
* Represents the outcome where the user has chosen to defer the upgrade.
16
+
* - Description: Indicates that the user has chosen to delay the upgrade process, opting to not update the application at this time.
14
17
*/
15
18
case notNow
16
19
/**
17
20
* Represents the outcome where the user has opened the App Store to perform the upgrade.
21
+
* - Description: Indicates that the user has initiated the upgrade process by opening the App Store to download the latest version of the application.
18
22
*/
19
23
case didOpenAppStoreToUpdate
20
24
/**
21
25
* Represents the outcome where an error occurred during the upgrade process.
22
26
* - Parameter error: The error that occurred during the upgrade process.
27
+
* - Description: Provides details about the specific error that prevented the upgrade process from completing successfully.
0 commit comments