Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New delegate protocol for letting the app know what's up #68

Merged
merged 1 commit into from

4 participants

@rhaining
  • added a delegate protocol to let the app know when things happen: alerts displayed, opted to rate/remind later/decline
Robert Haining added a delegate protocol to let the app know when things happen: ale…
…rt's displayed, opted to rate/remind later/decline
e475e36
@arashpayan arashpayan merged commit 5fba20e into arashpayan:master
@arashpayan
Owner

Thanks, @rhaining.

@kapsolas

I've tried to use the delegate, but it constantly fails. I didn't try to debug yet.

The code added to my application is:

[Appirater setDelegate:self];
[Appirater setAppId:APPIRATER_APP_ID_HERE];
[Appirater setDaysUntilPrompt:1];
[Appirater setUsesUntilPrompt:10];
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:2];
[Appirater appLaunched:YES];
[Appirater setDebug:YES];

The application crashes at in the sharedInstance method at the line where appirater.delegate is set with a SIGABRT.

appirater.delegate = _delegate;

@rhaining

Hmm what's the value of _delegate?

I've got it set to my application delegate, which implements the appirater delegate protocol. works on my end at least :-/

-rob

@AvinashP

Its not working for me too. I have set delegate to my App delegate object which implements AppiraterDelegate. Crashes with below error.

[Appirater setDelegate:self];
[Appirater setAppId:@"My_APP_ID"];
[Appirater setDaysUntilPrompt:0];
[Appirater setUsesUntilPrompt:3];
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:2];
[Appirater setDebug:YES];
[Appirater appLaunched:YES];

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

@rhaining

@AvinashP make sure you've updated Appirater.h, Appirater.m, & added AppiraterDelegate.h to your project. The 'delegate' is a property on the Appirater class. You'll also need to implement the AppiraterDelegate in your App Delegate object:

@interface MyAppDelegate : UIResponder <UIApplicationDelegate, AppiraterDelegate>{

-rob

@AvinashP

@rhaining I had done all these changes but still it was crashing. I think the issue was related to arc. I changed the delegate property from strong to nonatomic,assign and synthesized it in Appirator.m. It worked after that.

  • avinash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 25, 2012
  1. added a delegate protocol to let the app know when things happen: ale…

    Robert Haining authored
    …rt's displayed, opted to rate/remind later/decline
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.