Permalink
Browse files

Use class extension instead of internal category

  • Loading branch information...
a2 committed Oct 1, 2011
1 parent 0976202 commit fb76deddb9c67ac1770a44676dd00888a4564ffc
Showing with 121 additions and 126 deletions.
  1. +121 −126 Appirater.m
View
@@ -52,15 +52,132 @@
#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
@@ -255,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

0 comments on commit fb76ded

Please sign in to comment.