iRate.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // iRate.h
  3. //
  4. // Version 1.12.1
  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/iRate
  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. #import <StoreKit/StoreKit.h>
  46. #define IRATE_EXTERN UIKIT_EXTERN
  47. #else
  48. #import <Cocoa/Cocoa.h>
  49. #define IRATE_EXTERN APPKIT_EXTERN
  50. #endif
  51. //! Project version number for iRate.
  52. FOUNDATION_EXPORT double iRateVersionNumber;
  53. //! Project version string for iRate.
  54. FOUNDATION_EXPORT const unsigned char iRateVersionString[];
  55. IRATE_EXTERN NSUInteger const iRateAppStoreGameGenreID;
  56. IRATE_EXTERN NSString *const iRateErrorDomain;
  57. //localisation string keys
  58. IRATE_EXTERN NSString *const iRateMessageTitleKey; //iRateMessageTitle
  59. IRATE_EXTERN NSString *const iRateAppMessageKey; //iRateAppMessage
  60. IRATE_EXTERN NSString *const iRateGameMessageKey; //iRateGameMessage
  61. IRATE_EXTERN NSString *const iRateUpdateMessageKey; //iRateUpdateMessage
  62. IRATE_EXTERN NSString *const iRateCancelButtonKey; //iRateCancelButton
  63. IRATE_EXTERN NSString *const iRateRemindButtonKey; //iRateRemindButton
  64. IRATE_EXTERN NSString *const iRateRateButtonKey; //iRateRateButton
  65. //notification keys
  66. IRATE_EXTERN NSString *const iRateCouldNotConnectToAppStore;
  67. IRATE_EXTERN NSString *const iRateDidDetectAppUpdate;
  68. IRATE_EXTERN NSString *const iRateDidPromptForRating;
  69. IRATE_EXTERN NSString *const iRateUserDidAttemptToRateApp;
  70. IRATE_EXTERN NSString *const iRateUserDidDeclineToRateApp;
  71. IRATE_EXTERN NSString *const iRateUserDidRequestReminderToRateApp;
  72. IRATE_EXTERN NSString *const iRateDidOpenAppStore;
  73. typedef NS_ENUM(NSUInteger, iRateErrorCode)
  74. {
  75. iRateErrorBundleIdDoesNotMatchAppStore = 1,
  76. iRateErrorApplicationNotFoundOnAppStore,
  77. iRateErrorApplicationIsNotLatestVersion,
  78. iRateErrorCouldNotOpenRatingPageURL
  79. };
  80. @protocol iRateDelegate <NSObject>
  81. @optional
  82. - (void)iRateCouldNotConnectToAppStore:(NSError *)error;
  83. - (void)iRateDidDetectAppUpdate;
  84. - (BOOL)iRateShouldPromptForRating;
  85. - (void)iRateDidPromptForRating;
  86. - (void)iRateUserDidAttemptToRateApp;
  87. - (void)iRateUserDidDeclineToRateApp;
  88. - (void)iRateUserDidRequestReminderToRateApp;
  89. - (BOOL)iRateShouldOpenAppStore;
  90. - (void)iRateDidOpenAppStore;
  91. @end
  92. @interface iRate : NSObject
  93. + (instancetype)sharedInstance;
  94. //app store ID - this is only needed if your
  95. //bundle ID is not unique between iOS and Mac app stores
  96. @property (nonatomic, assign) NSUInteger appStoreID;
  97. //application details - these are set automatically
  98. @property (nonatomic, assign) NSUInteger appStoreGenreID;
  99. @property (nonatomic, copy) NSString *appStoreCountry;
  100. @property (nonatomic, copy) NSString *applicationName;
  101. @property (nonatomic, copy) NSString *applicationVersion;
  102. @property (nonatomic, copy) NSString *applicationBundleID;
  103. //usage settings - these have sensible defaults
  104. @property (nonatomic, assign) NSUInteger usesUntilPrompt;
  105. @property (nonatomic, assign) NSUInteger eventsUntilPrompt;
  106. @property (nonatomic, assign) float daysUntilPrompt;
  107. @property (nonatomic, assign) float usesPerWeekForPrompt;
  108. @property (nonatomic, assign) float remindPeriod;
  109. //message text, you may wish to customise these
  110. @property (nonatomic, copy) NSString *messageTitle;
  111. @property (nonatomic, copy) NSString *message;
  112. @property (nonatomic, copy) NSString *updateMessage;
  113. @property (nonatomic, copy) NSString *cancelButtonLabel;
  114. @property (nonatomic, copy) NSString *remindButtonLabel;
  115. @property (nonatomic, copy) NSString *rateButtonLabel;
  116. //debugging and prompt overrides
  117. @property (nonatomic, assign) BOOL useSKStoreReviewControllerIfAvailable;
  118. @property (nonatomic, assign) BOOL useUIAlertControllerIfAvailable;
  119. @property (nonatomic, assign) BOOL useAllAvailableLanguages;
  120. @property (nonatomic, assign) BOOL promptForNewVersionIfUserRated;
  121. @property (nonatomic, assign) BOOL onlyPromptIfLatestVersion;
  122. @property (nonatomic, assign) BOOL onlyPromptIfMainWindowIsAvailable;
  123. @property (nonatomic, assign) BOOL promptAtLaunch;
  124. @property (nonatomic, assign) BOOL verboseLogging;
  125. @property (nonatomic, assign) BOOL previewMode;
  126. //advanced properties for implementing custom behaviour
  127. @property (nonatomic, strong) NSURL *ratingsURL;
  128. @property (nonatomic, strong) NSDate *firstUsed;
  129. @property (nonatomic, strong) NSDate *lastReminded;
  130. @property (nonatomic, assign) NSUInteger usesCount;
  131. @property (nonatomic, assign) NSUInteger eventCount;
  132. @property (nonatomic, readonly) float usesPerWeek;
  133. @property (nonatomic, assign) BOOL declinedThisVersion;
  134. @property (nonatomic, readonly) BOOL declinedAnyVersion;
  135. @property (nonatomic, assign) BOOL ratedThisVersion;
  136. @property (nonatomic, readonly) BOOL ratedAnyVersion;
  137. @property (nonatomic, weak_delegate) id<iRateDelegate> delegate;
  138. //manually control behaviour
  139. - (BOOL)shouldPromptForRating;
  140. - (void)promptForRating;
  141. - (void)promptIfNetworkAvailable;
  142. - (void)promptIfAllCriteriaMet;
  143. - (void)openRatingsPageInAppStore;
  144. - (void)logEvent:(BOOL)deferPrompt;
  145. - (void)remindLater;
  146. @end
  147. #pragma clang diagnostic pop