Permalink
Browse files

Merge pull request #68 from rhaining/master

New delegate protocol for letting the app know what's up
  • Loading branch information...
arashpayan committed Sep 25, 2012
2 parents f314885 + e475e36 commit 5fba20e4681ca674a957297ab60c431b60a96158
Showing with 46 additions and 2 deletions.
  1. +7 −1 Appirater.h
  2. +18 −1 Appirater.m
  3. +21 −0 AppiraterDelegate.h
View
@@ -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
@@ -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
@@ -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

1 comment on commit 5fba20e

@jum

This comment has been minimized.

Show comment
Hide comment
@jum

jum Sep 26, 2012

This merge does not appear to work for me with XCode 4.2 (non-ARC):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Appirater setDelegate:]: unrecognized selector sent to instance 0x855f430'

There appears to be a synthesize missing, but simply adding one does not work due to the property being declared weak.

jum commented on 5fba20e Sep 26, 2012

This merge does not appear to work for me with XCode 4.2 (non-ARC):

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Appirater setDelegate:]: unrecognized selector sent to instance 0x855f430'

There appears to be a synthesize missing, but simply adding one does not work due to the property being declared weak.

Please sign in to comment.