Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Small fixes #31

Open
wants to merge 5 commits into from

1 participant

@a2
a2 commented
  • Localize user-visible strings
  • Rename interval user default keys
  • Create compile-time error if APPIRATER_APP_ID is default value
  • Use class extension instead of internal category
  • Fix memory leak on non-released NSURLConnection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 138 additions and 140 deletions.
  1. +6 −6 Appirater.h
  2. +132 −134 Appirater.m
View
12 Appirater.h
@@ -51,33 +51,33 @@ extern NSString *const kAppiraterDeclinedToRate;
/*
Your app's name.
*/
-#define APPIRATER_APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]
+#define APPIRATER_APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey: (NSString *) kCFBundleNameKey]
/*
This is the message your users will see once they've passed the day+launches
threshold.
*/
-#define APPIRATER_MESSAGE [NSString stringWithFormat:@"If you enjoy using %@, would you mind taking a moment to rate it? It won't take more than a minute. Thanks for your support!", APPIRATER_APP_NAME]
+#define APPIRATER_MESSAGE [NSString stringWithFormat: NSLocalizedString(@"If you enjoy using %@, would you mind taking a moment to rate it? It won't take more than a minute. Thanks for your support!", nil), APPIRATER_APP_NAME]
/*
This is the title of the message alert that users will see.
*/
-#define APPIRATER_MESSAGE_TITLE [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME]
+#define APPIRATER_MESSAGE_TITLE [NSString stringWithFormat: NSLocalizedString(@"Rate %@", nil), APPIRATER_APP_NAME]
/*
The text of the button that rejects reviewing the app.
*/
-#define APPIRATER_CANCEL_BUTTON @"No, Thanks"
+#define APPIRATER_CANCEL_BUTTON NSLocalizedString(@"No Thanks", nil)
/*
Text of button that will send user to app review page.
*/
-#define APPIRATER_RATE_BUTTON [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME]
+#define APPIRATER_RATE_BUTTON [NSString stringWithFormat: NSLocalizedString(@"Rate %@", nil), APPIRATER_APP_NAME]
/*
Text for button to remind the user to review later.
*/
-#define APPIRATER_RATE_LATER @"Remind me later"
+#define APPIRATER_RATE_LATER NSLocalizedString(@"Remind Me Later", nil)
/*
Users will need to have the same version of your app installed for this many
View
266 Appirater.m
@@ -38,26 +38,146 @@
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>
-NSString *const kAppiraterFirstUseDate = @"kAppiraterFirstUseDate";
-NSString *const kAppiraterUseCount = @"kAppiraterUseCount";
-NSString *const kAppiraterSignificantEventCount = @"kAppiraterSignificantEventCount";
-NSString *const kAppiraterCurrentVersion = @"kAppiraterCurrentVersion";
-NSString *const kAppiraterRatedCurrentVersion = @"kAppiraterRatedCurrentVersion";
-NSString *const kAppiraterDeclinedToRate = @"kAppiraterDeclinedToRate";
-NSString *const kAppiraterReminderRequestDate = @"kAppiraterReminderRequestDate";
+NSString *const kAppiraterFirstUseDate = @"Appirater.FirstUseDate";
+NSString *const kAppiraterUseCount = @"Appirater.UseCount";
+NSString *const kAppiraterSignificantEventCount = @"Appirater.SignificantEventCount";
+NSString *const kAppiraterCurrentVersion = @"Appirater.CurrentVersion";
+NSString *const kAppiraterRatedCurrentVersion = @"Appirater.RatedCurrentVersion";
+NSString *const kAppiraterDeclinedToRate = @"Appirater.DeclinedToRate";
+NSString *const kAppiraterReminderRequestDate = @"Appirater.ReminderRequestDate";
NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";
+#if APPIRATER_APP_ID == 301377083
+ #error "APPIRATER_APP_ID was not set in \"Appirater.h\""
+#endif
-@interface Appirater (hidden)
-- (BOOL)connectedToNetwork;
+@interface Appirater ()
+ (Appirater*)sharedInstance;
-- (void)showRatingAlert;
+- (BOOL)connectedToNetwork;
- (BOOL)ratingConditionsHaveBeenMet;
++ (void)appWillResignActive;
+- (void)hideRatingAlert;
- (void)incrementUseCount;
+- (void)showRatingAlert;
@end
-@implementation Appirater (hidden)
+@implementation Appirater
+
+@synthesize ratingAlert;
+
+- (void)incrementAndRate:(NSNumber*)_canPromptForRating {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [self incrementUseCount];
+
+ if ([_canPromptForRating boolValue] == YES &&
+ [self ratingConditionsHaveBeenMet] &&
+ [self connectedToNetwork])
+ {
+ [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
+ }
+
+ [pool release];
+}
+
+- (void)incrementSignificantEventAndRate:(NSNumber*)_canPromptForRating {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [self incrementSignificantEventCount];
+
+ if ([_canPromptForRating boolValue] == YES &&
+ [self ratingConditionsHaveBeenMet] &&
+ [self connectedToNetwork])
+ {
+ [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
+ }
+
+ [pool release];
+}
+
++ (void)appLaunched {
+ [Appirater appLaunched:YES];
+}
+
++ (void)appLaunched:(BOOL)canPromptForRating {
+ NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
+ [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
+ toTarget:[Appirater sharedInstance]
+ withObject:_canPromptForRating];
+ [_canPromptForRating release];
+}
+
+- (void)hideRatingAlert {
+ if (self.ratingAlert.visible) {
+ if (APPIRATER_DEBUG)
+ NSLog(@"APPIRATER Hiding Alert");
+ [self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO];
+ }
+}
+
++ (void)appWillResignActive {
+ if (APPIRATER_DEBUG)
+ NSLog(@"APPIRATER appWillResignActive");
+ [[Appirater sharedInstance] hideRatingAlert];
+}
+
++ (void)appEnteredForeground:(BOOL)canPromptForRating {
+ NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
+ [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
+ toTarget:[Appirater sharedInstance]
+ withObject:_canPromptForRating];
+ [_canPromptForRating release];
+}
+
++ (void)userDidSignificantEvent:(BOOL)canPromptForRating {
+ NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
+ [NSThread detachNewThreadSelector:@selector(incrementSignificantEventAndRate:)
+ toTarget:[Appirater sharedInstance]
+ withObject:_canPromptForRating];
+ [_canPromptForRating release];
+}
+
++ (void)rateApp {
+#if TARGET_IPHONE_SIMULATOR
+ NSLog(@"APPIRATER NOTE: iTunes App Store is not supported on the iOS simulator. Unable to open App Store page.");
+#else
+ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+ NSString *reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", APPIRATER_APP_ID]];
+ [userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion];
+ [userDefaults synchronize];
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]];
+#endif
+}
+
+- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
+ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+
+ switch (buttonIndex) {
+ case 0:
+ {
+ // they don't want to rate it
+ [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
+ [userDefaults synchronize];
+ break;
+ }
+ case 1:
+ {
+ // they want to rate it
+ [Appirater rateApp];
+ break;
+ }
+ case 2:
+ // remind them later
+ [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
+ [userDefaults synchronize];
+ break;
+ default:
+ break;
+ }
+}
+
+#pragma mark - Hidden
- (BOOL)connectedToNetwork {
// Create zero addy
@@ -85,7 +205,7 @@ - (BOOL)connectedToNetwork {
NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
- NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:self];
+ NSURLConnection *testConnection = [[[NSURLConnection alloc] initWithRequest:testRequest delegate:self] autorelease];
return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO;
}
@@ -252,125 +372,3 @@ - (void)incrementSignificantEventCount {
}
@end
-
-
-@interface Appirater ()
-- (void)hideRatingAlert;
-@end
-
-@implementation Appirater
-
-@synthesize ratingAlert;
-
-- (void)incrementAndRate:(NSNumber*)_canPromptForRating {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- [self incrementUseCount];
-
- if ([_canPromptForRating boolValue] == YES &&
- [self ratingConditionsHaveBeenMet] &&
- [self connectedToNetwork])
- {
- [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
- }
-
- [pool release];
-}
-
-- (void)incrementSignificantEventAndRate:(NSNumber*)_canPromptForRating {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- [self incrementSignificantEventCount];
-
- if ([_canPromptForRating boolValue] == YES &&
- [self ratingConditionsHaveBeenMet] &&
- [self connectedToNetwork])
- {
- [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
- }
-
- [pool release];
-}
-
-+ (void)appLaunched {
- [Appirater appLaunched:YES];
-}
-
-+ (void)appLaunched:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
-}
-
-- (void)hideRatingAlert {
- if (self.ratingAlert.visible) {
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Hiding Alert");
- [self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO];
- }
-}
-
-+ (void)appWillResignActive {
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER appWillResignActive");
- [[Appirater sharedInstance] hideRatingAlert];
-}
-
-+ (void)appEnteredForeground:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
-}
-
-+ (void)userDidSignificantEvent:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementSignificantEventAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
-}
-
-+ (void)rateApp {
-#if TARGET_IPHONE_SIMULATOR
- NSLog(@"APPIRATER NOTE: iTunes App Store is not supported on the iOS simulator. Unable to open App Store page.");
-#else
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSString *reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", APPIRATER_APP_ID]];
- [userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion];
- [userDefaults synchronize];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]];
-#endif
-}
-
-- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
-
- switch (buttonIndex) {
- case 0:
- {
- // they don't want to rate it
- [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
- [userDefaults synchronize];
- break;
- }
- case 1:
- {
- // they want to rate it
- [Appirater rateApp];
- break;
- }
- case 2:
- // remind them later
- [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
- [userDefaults synchronize];
- break;
- default:
- break;
- }
-}
-
-@end
Something went wrong with that request. Please try again.