Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adjust interface to allow better use as a Library #33

Open
wants to merge 5 commits into from

2 participants

@mk
mk commented
  • Move Strings to Appirator.bundle
  • Add German translations
  • Adjust API so APPIRATER_APP_ID is set at runtime:

    Remove APPIRATER_APP_ID and refactor the

    appLaunched:(BOOL)canPromptForRating
    

    method to take the appID at launch:

    appLaunchedWithAppStoreID:(int)appID canPromptForRating:(BOOL)canPromptForRating
    

    Also move strings to localization files.

mk and others added some commits
@mk mk Modifications to enable usage as a CocoaPods Library
 * Move Strings to Appirator.bundle
 * Add German translations
 * Adjust API so APPIRATER_APP_ID is set at runtime:

    Remove APPIRATER_APP_ID and refactor the

        appLaunched:(BOOL)canPromptForRating

    method to take the appID at launch:

        appLaunchedWithAppStoreID:(int)appID canPromptForRating:(BOOL)canPromptForRating

    Also move strings to localization files.
7ea98c6
@triplef triplef Use #ifs for APPIRATER_DEBUG instead of runtime check. a583843
@triplef triplef Use GCD instead of threads.
Was previously creating a new thread for every call to
+userDidSignificantEvent, +appEnteredForeground, and +appLaunched.
1c61736
@triplef triplef Use GCD dispatch_once instead of @synchronized for +sharedInstance. 797abff
@triplef triplef Tweak: use UKKit constant instead of string. 810029b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2011
  1. @mk

    Modifications to enable usage as a CocoaPods Library

    mk authored
     * Move Strings to Appirator.bundle
     * Add German translations
     * Adjust API so APPIRATER_APP_ID is set at runtime:
    
        Remove APPIRATER_APP_ID and refactor the
    
            appLaunched:(BOOL)canPromptForRating
    
        method to take the appID at launch:
    
            appLaunchedWithAppStoreID:(int)appID canPromptForRating:(BOOL)canPromptForRating
    
        Also move strings to localization files.
Commits on Nov 23, 2011
  1. @triplef @mk

    Use #ifs for APPIRATER_DEBUG instead of runtime check.

    triplef authored mk committed
  2. @triplef @mk

    Use GCD instead of threads.

    triplef authored mk committed
    Was previously creating a new thread for every call to
    +userDidSignificantEvent, +appEnteredForeground, and +appLaunched.
  3. @triplef @mk
  4. @triplef @mk

    Tweak: use UKKit constant instead of string.

    triplef authored mk committed
This page is out of date. Refresh to see the latest.
View
11 Appirater.bundle/de.lproj/Appirater.strings
@@ -0,0 +1,11 @@
+/*
+ Appirater.strings
+ Appirater
+
+ Created by Martin Kavalar on 11/15/10.
+ */
+"AppiraterMessage" = "Gefällt Dir %@? Dann bewerte es doch kurz. Es dauert nur eine Minute. Danke für Deine Unterstützung!";
+"AppiraterTitle" = "%@ bewerten";
+"AppiraterCancelButton" = "Nein, danke";
+"AppiraterRateLaterButton" = "Später nochmal fragen";
+"AppiraterRateButton" = "%@ bewerten";
View
11 Appirater.bundle/en.lproj/Appirater.strings
@@ -0,0 +1,11 @@
+/*
+ Appirater.strings
+ Appirater
+
+ Created by Martin Kavalar on 11/15/10.
+ */
+"AppiraterMessage" = "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!";
+"AppiraterTitle" = "Rate %@";
+"AppiraterCancelButton" = "No, Thanks";
+"AppiraterRateLaterButton" = "Remind me later";
+"AppiraterRateButton" = "Rate %@";
View
51 Appirater.h
@@ -43,41 +43,18 @@ extern NSString *const kAppiraterCurrentVersion;
extern NSString *const kAppiraterRatedCurrentVersion;
extern NSString *const kAppiraterDeclinedToRate;
-/*
- Place your Apple generated software id here.
- */
-#define APPIRATER_APP_ID 301377083
+#define kAppiraterBundleName @"Appirater.bundle"
-/*
- Your app's name.
- */
-#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]
+NSBundle *appiraterBundle(void);
-/*
- This is the title of the message alert that users will see.
- */
-#define APPIRATER_MESSAGE_TITLE [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME]
+ /*
+ Your app's name.
+ */
+#define APPIRATER_APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]
-/*
- The text of the button that rejects reviewing the app.
- */
-#define APPIRATER_CANCEL_BUTTON @"No, Thanks"
+#define AppiraterLocalize(StringToken) NSLocalizedStringFromTableInBundle(StringToken, @"Appirater", appiraterBundle(), @"")
-/*
- Text of button that will send user to app review page.
- */
-#define APPIRATER_RATE_BUTTON [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME]
-
-/*
- Text for button to remind the user to review later.
- */
-#define APPIRATER_RATE_LATER @"Remind me later"
/*
Users will need to have the same version of your app installed for this many
@@ -118,10 +95,10 @@ extern NSString *const kAppiraterDeclinedToRate;
#define APPIRATER_TIME_BEFORE_REMINDING 1 // double
/*
- 'YES' will show the Appirater alert everytime. Useful for testing how your message
+ '1' will show the Appirater alert everytime. Useful for testing how your message
looks and making sure the link to your app's review page works.
*/
-#define APPIRATER_DEBUG NO
+#define APPIRATER_DEBUG 0
@interface Appirater : NSObject <UIAlertViewDelegate> {
@@ -131,14 +108,6 @@ extern NSString *const kAppiraterDeclinedToRate;
@property(nonatomic, retain) UIAlertView *ratingAlert;
/*
- DEPRECATED: While still functional, it's better to use
- appLaunched:(BOOL)canPromptForRating instead.
-
- Calls [Appirater appLaunched:YES]. See appLaunched: for details of functionality.
- */
-+ (void)appLaunched;
-
-/*
Tells Appirater that the app has launched, and on devices that do NOT
support multitasking, the 'uses' count will be incremented. You should
call this method at the end of your application delegate's
@@ -151,7 +120,7 @@ extern NSString *const kAppiraterDeclinedToRate;
can also be triggered by appEnteredForeground: and userDidSignificantEvent:
(as long as you pass YES for canPromptForRating in those methods).
*/
-+ (void)appLaunched:(BOOL)canPromptForRating;
++ (void)appLaunchedWithAppStoreID:(int)appID canPromptForRating:(BOOL)canPromptForRating;
/*
Tells Appirater that the app was brought to the foreground on multitasking
View
119 Appirater.m
@@ -49,6 +49,17 @@
NSString *templateReviewURL = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";
+NSBundle *appiraterBundle(void) {
+ static NSBundle* bundle = nil;
+ if (!bundle) {
+ NSString* path = [[[NSBundle mainBundle] resourcePath]
+ stringByAppendingPathComponent:kAppiraterBundleName];
+ bundle = [[NSBundle bundleWithPath:path] retain];
+ }
+ return bundle;
+}
+
+
@interface Appirater (hidden)
- (BOOL)connectedToNetwork;
+ (Appirater*)sharedInstance;
@@ -92,32 +103,29 @@ - (BOOL)connectedToNetwork {
+ (Appirater*)sharedInstance {
static Appirater *appirater = nil;
- if (appirater == nil)
- {
- @synchronized(self) {
- if (appirater == nil) {
- appirater = [[Appirater alloc] init];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:@"UIApplicationWillResignActiveNotification" object:nil];
- }
- }
- }
+ static dispatch_once_t appiraterOnceToken;
+ dispatch_once(&appiraterOnceToken, ^{
+ appirater = [[Appirater alloc] init];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
+ });
return appirater;
}
- (void)showRatingAlert {
- UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE
- message:APPIRATER_MESSAGE
- delegate:self
- cancelButtonTitle:APPIRATER_CANCEL_BUTTON
- otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil] autorelease];
+ UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:AppiraterLocalize(@"AppiraterTitle"), APPIRATER_APP_NAME]
+ message:[NSString stringWithFormat:AppiraterLocalize(@"AppiraterMessage"), APPIRATER_APP_NAME]
+ delegate:self
+ cancelButtonTitle:AppiraterLocalize(@"AppiraterCancelButton")
+ otherButtonTitles:[NSString stringWithFormat:AppiraterLocalize(@"AppiraterRateButton"), APPIRATER_APP_NAME], AppiraterLocalize(@"AppiraterRateLaterButton"), nil] autorelease];
self.ratingAlert = alertView;
[alertView show];
}
- (BOOL)ratingConditionsHaveBeenMet {
- if (APPIRATER_DEBUG)
- return YES;
+#if APPIRATER_DEBUG
+ return YES;
+#endif
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
@@ -168,8 +176,9 @@ - (void)incrementUseCount {
[userDefaults setObject:version forKey:kAppiraterCurrentVersion];
}
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Tracking version: %@", trackingVersion);
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER Tracking version: %@", trackingVersion);
+#endif
if ([trackingVersion isEqualToString:version])
{
@@ -185,8 +194,9 @@ - (void)incrementUseCount {
int useCount = [userDefaults integerForKey:kAppiraterUseCount];
useCount++;
[userDefaults setInteger:useCount forKey:kAppiraterUseCount];
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Use count: %d", useCount);
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER Use count: %d", useCount);
+#endif
}
else
{
@@ -216,8 +226,9 @@ - (void)incrementSignificantEventCount {
[userDefaults setObject:version forKey:kAppiraterCurrentVersion];
}
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Tracking version: %@", trackingVersion);
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER Tracking version: %@", trackingVersion);
+#endif
if ([trackingVersion isEqualToString:version])
{
@@ -233,8 +244,9 @@ - (void)incrementSignificantEventCount {
int sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount];
sigEventCount++;
[userDefaults setInteger:sigEventCount forKey:kAppiraterSignificantEventCount];
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Significant event count: %d", sigEventCount);
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER Significant event count: %d", sigEventCount);
+#endif
}
else
{
@@ -262,76 +274,63 @@ @implementation Appirater
@synthesize ratingAlert;
-- (void)incrementAndRate:(NSNumber*)_canPromptForRating {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
+- (void)incrementAndRate:(BOOL)canPromptForRating {
[self incrementUseCount];
- if ([_canPromptForRating boolValue] == YES &&
+ if (canPromptForRating == YES &&
[self ratingConditionsHaveBeenMet] &&
[self connectedToNetwork])
{
[self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
}
-
- [pool release];
}
-- (void)incrementSignificantEventAndRate:(NSNumber*)_canPromptForRating {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
+- (void)incrementSignificantEventAndRate:(BOOL)canPromptForRating {
[self incrementSignificantEventCount];
- if ([_canPromptForRating boolValue] == YES &&
+ if (canPromptForRating == YES &&
[self ratingConditionsHaveBeenMet] &&
[self connectedToNetwork])
{
[self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO];
}
-
- [pool release];
}
-+ (void)appLaunched {
- [Appirater appLaunched:YES];
-}
+static int appID;
-+ (void)appLaunched:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
++ (void)appLaunchedWithAppStoreID:(int)anAppID canPromptForRating:(BOOL)canPromptForRating {
+ appID = anAppID;
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+ [[Appirater sharedInstance] incrementAndRate:canPromptForRating];
+ });
}
- (void)hideRatingAlert {
if (self.ratingAlert.visible) {
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER Hiding Alert");
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER Hiding Alert");
+#endif
[self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO];
}
}
+ (void)appWillResignActive {
- if (APPIRATER_DEBUG)
- NSLog(@"APPIRATER appWillResignActive");
+#if APPIRATER_DEBUG
+ NSLog(@"APPIRATER appWillResignActive");
+#endif
[[Appirater sharedInstance] hideRatingAlert];
}
+ (void)appEnteredForeground:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+ [[Appirater sharedInstance] incrementAndRate:canPromptForRating];
+ });
}
+ (void)userDidSignificantEvent:(BOOL)canPromptForRating {
- NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating];
- [NSThread detachNewThreadSelector:@selector(incrementSignificantEventAndRate:)
- toTarget:[Appirater sharedInstance]
- withObject:_canPromptForRating];
- [_canPromptForRating release];
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+ [[Appirater sharedInstance] incrementSignificantEventAndRate:canPromptForRating];
+ });
}
+ (void)rateApp {
@@ -339,7 +338,7 @@ + (void)rateApp {
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]];
+ NSString *reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", appID]];
[userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion];
[userDefaults synchronize];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]];
View
3  README.md
@@ -9,10 +9,9 @@ Getting Started
---------------
1. Add the Appirater code into your project
2. Add the `CFNetwork` and `SystemConfiguration` frameworks to your project
-3. Call `[Appirater appLaunched:YES]` at the end of your app delegate's `application:didFinishLaunchingWithOptions:` method.
+3. Call `[Appirater appLaunchedWithAppStoreID:APPIRATER_APP_ID canPromptForRating:YES]` at the end of your app delegate's `application:didFinishLaunchingWithOptions:` method, where `APPIRATER_APP_ID` is your Apple provided software id.
4. Call `[Appirater appEnteredForeground:YES]` in your app delegate's `applicationWillEnterForeground:` method.
5. (OPTIONAL) Call `[Appirater userDidSignificantEvent:YES]` when the user does something 'significant' in the app.
-6. Finally, set the `APPIRATER_APP_ID` in `Appirater.h` to your Apple provided software id.
License
-------
Something went wrong with that request. Please try again.