iRate.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // iRate.h
  3. //
  4. // Version 1.7.4
  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. #import <Availability.h>
  33. #undef weak_delegate
  34. #if __has_feature(objc_arc_weak) && \
  35. (!(defined __MAC_OS_X_VERSION_MIN_REQUIRED) || \
  36. __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8)
  37. #define weak_delegate weak
  38. #else
  39. #define weak_delegate unsafe_unretained
  40. #endif
  41. #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
  42. #import <UIKit/UIKit.h>
  43. #else
  44. #import <Cocoa/Cocoa.h>
  45. #endif
  46. extern NSUInteger const iRateAppStoreGameGenreID;
  47. extern NSString *const iRateErrorDomain;
  48. //localisation string keys
  49. static NSString *const iRateMessageTitleKey = @"iRateMessageTitle";
  50. static NSString *const iRateAppMessageKey = @"iRateAppMessage";
  51. static NSString *const iRateGameMessageKey = @"iRateGameMessage";
  52. static NSString *const iRateCancelButtonKey = @"iRateCancelButton";
  53. static NSString *const iRateRemindButtonKey = @"iRateRemindButton";
  54. static NSString *const iRateRateButtonKey = @"iRateRateButton";
  55. /*
  56. Users will need to have the same version of your app installed for this many
  57. days before they will be prompted to rate it.
  58. */
  59. #if VERSION_FREE
  60. #define APPIRATER_DAYS_UNTIL_PROMPT 4 // double
  61. #else
  62. #define APPIRATER_DAYS_UNTIL_PROMPT 10 // double
  63. #endif
  64. /*
  65. An example of a 'use' would be if the user launched the app. Bringing the app
  66. into the foreground (on devices that support it) would also be considered
  67. a 'use'.
  68. Users need to 'use' the same version of the app this many times before
  69. before they will be prompted to rate it.
  70. */
  71. #define APPIRATER_USES_UNTIL_PROMPT -1 // integer
  72. /*
  73. Once the rating alert is presented to the user, they might select
  74. 'Remind me later'. This value specifies how long (in days) Appirater
  75. will wait before reminding them.
  76. */
  77. #if VERSION_FREE
  78. #define APPIRATER_TIME_BEFORE_REMINDING 12 // double
  79. #else
  80. #define APPIRATER_TIME_BEFORE_REMINDING 30 // double
  81. #endif
  82. /*
  83. 用户选择了 No 按钮几次之后,不再弹出Appirater评价界面.
  84. */
  85. #if VERSION_FREE
  86. #define APPIRATER_PROMPT_TIMES_UNTIL_REJECT 3 // double
  87. #else
  88. #define APPIRATER_PROMPT_TIMES_UNTIL_REJECT 2 // double
  89. #endif
  90. typedef enum
  91. {
  92. iRateErrorBundleIdDoesNotMatchAppStore = 1,
  93. iRateErrorApplicationNotFoundOnAppStore,
  94. iRateErrorApplicationIsNotLatestVersion
  95. }
  96. iRateErrorCode;
  97. @protocol iRateDelegate <NSObject>
  98. @optional
  99. - (void)iRateCouldNotConnectToAppStore:(NSError *)error;
  100. - (void)iRateDidDetectAppUpdate;
  101. - (BOOL)iRateShouldPromptForRating;
  102. - (void)iRateDidPromptForRating;
  103. - (void)iRateUserDidAttemptToRateApp;
  104. - (void)iRateUserDidDeclineToRateApp;
  105. - (void)iRateUserDidRequestReminderToRateApp;
  106. - (BOOL)iRateShouldOpenAppStore;
  107. - (void)iRateDidPresentStoreKitModal;
  108. - (void)iRateDidDismissStoreKitModal;
  109. @end
  110. @interface iRate : NSObject
  111. + (iRate *)sharedInstance;
  112. //app store ID - this is only needed if your
  113. //bundle ID is not unique between iOS and Mac app stores
  114. @property (nonatomic, assign) NSUInteger appStoreID;
  115. //application details - these are set automatically
  116. @property (nonatomic, assign) NSUInteger appStoreGenreID;
  117. @property (nonatomic, copy) NSString *appStoreCountry;
  118. @property (nonatomic, copy) NSString *applicationName;
  119. @property (nonatomic, copy) NSString *applicationVersion;
  120. @property (nonatomic, copy) NSString *applicationBundleID;
  121. //usage settings - these have sensible defaults
  122. @property (nonatomic, assign) NSUInteger usesUntilPrompt;// 使用几次后开始弹出
  123. @property (nonatomic, assign) NSUInteger eventsUntilPrompt;
  124. @property (nonatomic, assign) float daysUntilPrompt;// 多少天后开始弹出
  125. @property (nonatomic, assign) float usesPerWeekForPrompt;
  126. @property (nonatomic, assign) float remindPeriod;// 选择“稍后提醒我”后的再提醒时间间隔
  127. //message text, you may wish to customise these
  128. @property (nonatomic, copy) NSString *messageTitle;
  129. @property (nonatomic, copy) NSString *message;
  130. @property (nonatomic, copy) NSString *cancelButtonLabel;
  131. @property (nonatomic, copy) NSString *remindButtonLabel;
  132. @property (nonatomic, copy) NSString *rateButtonLabel;
  133. //debugging and prompt overrides
  134. @property (nonatomic, assign) BOOL useAllAvailableLanguages;
  135. @property (nonatomic, assign) BOOL disableAlertViewResizing;
  136. @property (nonatomic, assign) BOOL promptAgainForEachNewVersion;
  137. @property (nonatomic, assign) BOOL onlyPromptIfLatestVersion;
  138. @property (nonatomic, assign) BOOL onlyPromptIfMainWindowIsAvailable;
  139. @property (nonatomic, assign) BOOL displayAppUsingStorekitIfAvailable;
  140. @property (nonatomic, assign) BOOL promptAtLaunch;// 启动或者回到前台就尝试提醒
  141. @property (nonatomic, assign) BOOL verboseLogging;
  142. @property (nonatomic, assign) BOOL previewMode;
  143. //advanced properties for implementing custom behaviour
  144. @property (nonatomic, strong) NSURL *ratingsURL;
  145. @property (nonatomic, strong) NSDate *firstUsed;
  146. @property (nonatomic, strong) NSDate *lastReminded;
  147. @property (nonatomic, assign) NSUInteger usesCount;
  148. @property (nonatomic, assign) NSUInteger eventCount;
  149. @property (nonatomic, readonly) float usesPerWeek;
  150. @property (nonatomic, assign) BOOL declinedThisVersion;
  151. @property (nonatomic, readonly) BOOL declinedAnyVersion;
  152. @property (nonatomic, assign) BOOL ratedThisVersion;
  153. @property (nonatomic, readonly) BOOL ratedAnyVersion;
  154. @property (nonatomic, weak_delegate) id<iRateDelegate> delegate;
  155. //manually control behaviour
  156. - (BOOL)shouldPromptForRating;
  157. - (void)promptForRating;
  158. - (void)promptIfNetworkAvailable;
  159. - (void)openRatingsPageInAppStore;
  160. - (void)logEvent:(BOOL)deferPrompt;
  161. - (void)remindMeLater;
  162. - (void)appLaunched;
  163. @end