iVersion.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // iVersion.h
  3. //
  4. // Version 1.11.5
  5. //
  6. // Created by Nick Lockwood on 26/01/2011.
  7. // Copyright 2011 Charcoal Design
  8. //
  9. // Distributed under the permissive zlib license
  10. // Get the latest version from here:
  11. //
  12. // https://github.com/nicklockwood/iVersion
  13. //
  14. // This software is provided 'as-is', without any express or implied
  15. // warranty. In no event will the authors be held liable for any damages
  16. // arising from the use of this software.
  17. //
  18. // Permission is granted to anyone to use this software for any purpose,
  19. // including commercial applications, and to alter it and redistribute it
  20. // freely, subject to the following restrictions:
  21. //
  22. // 1. The origin of this software must not be misrepresented; you must not
  23. // claim that you wrote the original software. If you use this software
  24. // in a product, an acknowledgment in the product documentation would be
  25. // appreciated but is not required.
  26. //
  27. // 2. Altered source versions must be plainly marked as such, and must not be
  28. // misrepresented as being the original software.
  29. //
  30. // 3. This notice may not be removed or altered from any source distribution.
  31. //
  32. #pragma clang diagnostic push
  33. #pragma clang diagnostic ignored "-Wobjc-missing-property-synthesis"
  34. #import <Availability.h>
  35. #undef weak_delegate
  36. #if __has_feature(objc_arc_weak) && \
  37. (TARGET_OS_IPHONE || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8)
  38. #define weak_delegate weak
  39. #else
  40. #define weak_delegate unsafe_unretained
  41. #endif
  42. #import <TargetConditionals.h>
  43. #if TARGET_OS_IPHONE
  44. #import <UIKit/UIKit.h>
  45. #define IVERSION_USE_STOREKIT 1
  46. #define IVERSION_EXTERN UIKIT_EXTERN
  47. #else
  48. #import <Cocoa/Cocoa.h>
  49. #define IVERSION_EXTERN APPKIT_EXTERN
  50. #endif
  51. #if defined(IVERSION_USE_STOREKIT) && IVERSION_USE_STOREKIT
  52. #import <StoreKit/StoreKit.h>
  53. #endif
  54. extern NSString *const iVersionErrorDomain;
  55. //localisation string keys
  56. IVERSION_EXTERN NSString *const iVersionInThisVersionTitleKey; //iVersionInThisVersionTitle
  57. IVERSION_EXTERN NSString *const iVersionUpdateAvailableTitleKey; //iVersionUpdateAvailableTitle
  58. IVERSION_EXTERN NSString *const iVersionVersionLabelFormatKey; //iVersionVersionLabelFormat
  59. IVERSION_EXTERN NSString *const iVersionOKButtonKey; //iVersionOKButton
  60. IVERSION_EXTERN NSString *const iVersionIgnoreButtonKey; //iVersionIgnoreButton
  61. IVERSION_EXTERN NSString *const iVersionRemindButtonKey; //iVersionRemindButton
  62. IVERSION_EXTERN NSString *const iVersionDownloadButtonKey; //iVersionDownloadButton
  63. typedef NS_ENUM(NSUInteger, iVersionErrorCode)
  64. {
  65. iVersionErrorBundleIdDoesNotMatchAppStore = 1,
  66. iVersionErrorApplicationNotFoundOnAppStore,
  67. iVersionErrorOSVersionNotSupported
  68. };
  69. typedef NS_ENUM(NSInteger, iVersionUpdatePriority)
  70. {
  71. iVersionUpdatePriorityDefault = 0,
  72. iVersionUpdatePriorityLow = 1,
  73. iVersionUpdatePriorityMedium = 2,
  74. iVersionUpdatePriorityHigh = 3
  75. };
  76. @interface NSString(iVersion)
  77. - (NSComparisonResult)compareVersion:(NSString *)version;
  78. - (NSComparisonResult)compareVersionDescending:(NSString *)version;
  79. @end
  80. @protocol iVersionDelegate <NSObject>
  81. @optional
  82. - (BOOL)iVersionShouldCheckForNewVersion;
  83. - (void)iVersionDidNotDetectNewVersion;
  84. - (void)iVersionVersionCheckDidFailWithError:(NSError *)error;
  85. - (void)iVersionDidDetectNewVersion:(NSString *)version details:(NSString *)versionDetails;
  86. - (BOOL)iVersionShouldDisplayNewVersion:(NSString *)version details:(NSString *)versionDetails;
  87. - (BOOL)iVersionShouldDisplayCurrentVersionDetails:(NSString *)versionDetails;
  88. - (void)iVersionUserDidAttemptToDownloadUpdate:(NSString *)version;
  89. - (void)iVersionUserDidRequestReminderForUpdate:(NSString *)version;
  90. - (void)iVersionUserDidIgnoreUpdate:(NSString *)version;
  91. - (BOOL)iVersionShouldOpenAppStore;
  92. - (void)iVersionDidPresentStoreKitModal;
  93. - (void)iVersionDidDismissStoreKitModal;
  94. @end
  95. @interface iVersion : NSObject
  96. + (iVersion *)sharedInstance;
  97. //app store ID - this is only needed if your
  98. //bundle ID is not unique between iOS and Mac app stores
  99. @property (nonatomic, assign) NSUInteger appStoreID;
  100. //application details - these are set automatically
  101. @property (nonatomic, copy) NSString *applicationVersion;
  102. @property (nonatomic, copy) NSString *applicationBundleID;
  103. @property (nonatomic, copy) NSString *appStoreCountry;
  104. //usage settings - these have sensible defaults
  105. @property (nonatomic, assign) BOOL showOnFirstLaunch;
  106. @property (nonatomic, assign) BOOL groupNotesByVersion;
  107. @property (nonatomic, assign) float checkPeriod;
  108. @property (nonatomic, assign) float remindPeriod;
  109. //message text - you may wish to customise these
  110. @property (nonatomic, copy) NSString *inThisVersionTitle;
  111. @property (nonatomic, copy) NSString *updateAvailableTitle;
  112. @property (nonatomic, copy) NSString *versionLabelFormat;
  113. @property (nonatomic, copy) NSString *okButtonLabel;
  114. @property (nonatomic, copy) NSString *ignoreButtonLabel;
  115. @property (nonatomic, copy) NSString *remindButtonLabel;
  116. @property (nonatomic, copy) NSString *downloadButtonLabel;
  117. @property (nonatomic, copy) NSString *versionDetailsDefault;
  118. //debugging and prompt overrides
  119. @property (nonatomic, assign) iVersionUpdatePriority updatePriority;
  120. @property (nonatomic, assign) BOOL useUIAlertControllerIfAvailable;
  121. @property (nonatomic, assign) BOOL useAllAvailableLanguages;
  122. @property (nonatomic, assign) BOOL onlyPromptIfMainWindowIsAvailable;
  123. @property (nonatomic, assign) BOOL useAppStoreDetailsIfNoPlistEntryFound;
  124. @property (nonatomic, assign) BOOL checkAtLaunch;
  125. @property (nonatomic, assign) BOOL verboseLogging;
  126. @property (nonatomic, assign) BOOL previewMode;
  127. //advanced properties for implementing custom behaviour
  128. @property (nonatomic, copy) NSString *remoteVersionsPlistURL;
  129. @property (nonatomic, copy) NSString *localVersionsPlistPath;
  130. @property (nonatomic, copy) NSString *ignoredVersion;
  131. @property (nonatomic, strong) NSDate *lastChecked;
  132. @property (nonatomic, strong) NSDate *lastReminded;
  133. @property (nonatomic, strong) NSURL *updateURL;
  134. @property (nonatomic, assign) BOOL viewedVersionDetails;
  135. @property (nonatomic, weak_delegate) id<iVersionDelegate> delegate;
  136. //manually control behaviour
  137. - (BOOL)openAppPageInAppStore;
  138. - (void)checkIfNewVersion;
  139. - (NSString *)versionDetails;
  140. - (BOOL)shouldCheckForNewVersion;
  141. - (void)checkForNewVersion;
  142. - (NSString *)localizedStringForKey:(NSString *)key withDefault:(NSString *)defaultString;
  143. @end
  144. #pragma clang diagnostic pop