Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added a delegate protocol to let the app know when things happen: ale…

…rt's displayed, opted to rate/remind later/decline
  • Loading branch information...
commit e475e36fe04a843d99be2cef9b3626d3e1d37595 1 parent f314885
Robert Haining authored
Showing with 46 additions and 2 deletions.
  1. +7 −1 Appirater.h
  2. +18 −1 Appirater.m
  3. +21 −0 AppiraterDelegate.h
View
8 Appirater.h
@@ -35,6 +35,7 @@
*/
#import <Foundation/Foundation.h>
+#import "AppiraterDelegate.h"
extern NSString *const kAppiraterFirstUseDate;
extern NSString *const kAppiraterUseCount;
@@ -83,13 +84,13 @@ extern NSString *const kAppiraterReminderRequestDate;
*/
#define APPIRATER_RATE_LATER NSLocalizedStringFromTable(@"Remind me later", @"AppiraterLocalizable", nil)
-
@interface Appirater : NSObject <UIAlertViewDelegate> {
UIAlertView *ratingAlert;
}
@property(nonatomic, strong) UIAlertView *ratingAlert;
+@property(nonatomic, weak) NSObject <AppiraterDelegate> *delegate;
/*
Tells Appirater that the app has launched, and on devices that do NOT
@@ -203,6 +204,11 @@ extern NSString *const kAppiraterReminderRequestDate;
*/
+ (void) setDebug:(BOOL)debug;
+/*
+ Set the delegate if you want to know when Appirater does something
+ */
++ (void)setDelegate:(id<AppiraterDelegate>)delegate;
+
@end
View
19 Appirater.m
@@ -54,6 +54,7 @@
static NSInteger _significantEventsUntilPrompt = -1;
static double _timeBeforeReminding = 1;
static BOOL _debug = NO;
+static id<AppiraterDelegate> _delegate;
@interface Appirater ()
- (BOOL)connectedToNetwork;
@@ -91,7 +92,9 @@ + (void) setTimeBeforeReminding:(double)value {
+ (void) setDebug:(BOOL)debug {
_debug = debug;
}
-
++ (void)setDelegate:(id<AppiraterDelegate>)delegate{
+ _delegate = delegate;
+}
- (BOOL)connectedToNetwork {
// Create zero addy
@@ -131,6 +134,7 @@ + (Appirater*)sharedInstance {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
appirater = [[Appirater alloc] init];
+ appirater.delegate = _delegate;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:
UIApplicationWillResignActiveNotification object:nil];
});
@@ -147,6 +151,10 @@ - (void)showRatingAlert {
otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil];
self.ratingAlert = alertView;
[alertView show];
+
+ if(self.delegate && [self.delegate respondsToSelector:@selector(appiraterDidDisplayAlert:)]){
+ [self.delegate appiraterDidDisplayAlert:self];
+ }
}
- (BOOL)ratingConditionsHaveBeenMet {
@@ -376,18 +384,27 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
// they don't want to rate it
[userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
[userDefaults synchronize];
+ if(self.delegate && [self.delegate respondsToSelector:@selector(appiraterDidDeclineToRate:)]){
+ [self.delegate appiraterDidDeclineToRate:self];
+ }
break;
}
case 1:
{
// they want to rate it
[Appirater rateApp];
+ if(self.delegate && [self.delegate respondsToSelector:@selector(appiraterDidOptToRate:)]){
+ [self.delegate appiraterDidOptToRate:self];
+ }
break;
}
case 2:
// remind them later
[userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate];
[userDefaults synchronize];
+ if(self.delegate && [self.delegate respondsToSelector:@selector(appiraterDidOptToRemindLater:)]){
+ [self.delegate appiraterDidOptToRemindLater:self];
+ }
break;
default:
break;
View
21 AppiraterDelegate.h
@@ -0,0 +1,21 @@
+//
+// AppiraterDelegate.h
+// Banana Stand
+//
+// Created by Robert Haining on 9/25/12.
+// Copyright (c) 2012 News.me. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class Appirater;
+
+@protocol AppiraterDelegate <NSObject>
+
+@optional
+-(void)appiraterDidDisplayAlert:(Appirater *)appirater;
+-(void)appiraterDidDeclineToRate:(Appirater *)appirater;
+-(void)appiraterDidOptToRate:(Appirater *)appirater;
+-(void)appiraterDidOptToRemindLater:(Appirater *)appirater;
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.