project_files/HedgewarsMobile/Classes/Appirater.m
author Xeli
Tue, 28 Jun 2011 17:54:27 +0200
branchhedgeroid
changeset 5369 0ce1ef75c08f
parent 4504 8906b2409d97
child 5483 fc755bb8096d
permissions -rw-r--r--
Removed absolute path to libhwengine.so, the library must be preloaded from Java now. Which automagically knows where libhwengine.so is!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4504
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     1
/*
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     2
 This file is part of Appirater.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     3
 
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     4
 Copyright (c) 2010, Arash Payan
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     5
 All rights reserved.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     6
 
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     7
 Permission is hereby granted, free of charge, to any person
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     8
 obtaining a copy of this software and associated documentation
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
     9
 files (the "Software"), to deal in the Software without
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    10
 restriction, including without limitation the rights to use,
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    11
 copy, modify, merge, publish, distribute, sublicense, and/or sell
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    12
 copies of the Software, and to permit persons to whom the
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    13
 Software is furnished to do so, subject to the following
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    14
 conditions:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    15
 
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    16
 The above copyright notice and this permission notice shall be
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    17
 included in all copies or substantial portions of the Software.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    18
 
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    19
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    20
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    21
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    22
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    23
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    24
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    25
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    26
 OTHER DEALINGS IN THE SOFTWARE.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    27
 */
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    28
/*
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    29
 * Appirater.m
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    30
 * appirater
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    31
 *
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    32
 * Created by Arash Payan on 9/5/09.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    33
 * http://arashpayan.com
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    34
 * Copyright 2010 Arash Payan. All rights reserved.
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    35
 */
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    36
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    37
#import "Appirater.h"
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    38
#import <SystemConfiguration/SCNetworkReachability.h>
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    39
#import <netinet/in.h>
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    40
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    41
NSString *const kAppiraterLaunchDate            = @"kAppiraterLaunchDate";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    42
NSString *const kAppiraterLaunchCount           = @"kAppiraterLaunchCount";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    43
NSString *const kAppiraterCurrentVersion        = @"kAppiraterCurrentVersion";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    44
NSString *const kAppiraterRatedCurrentVersion   = @"kAppiraterRatedCurrentVersion";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    45
NSString *const kAppiraterDeclinedToRate        = @"kAppiraterDeclinedToRate";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    46
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    47
NSString *templateReviewURL = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=APP_ID&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software";
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    48
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    49
@interface Appirater (hidden)
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    50
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    51
-(BOOL) connectedToNetwork;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    52
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    53
@end
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    54
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    55
@implementation Appirater (hidden)
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    56
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    57
-(BOOL) connectedToNetwork {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    58
    // Create zero addy
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    59
    struct sockaddr_in zeroAddress;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    60
    bzero(&zeroAddress, sizeof(zeroAddress));
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    61
    zeroAddress.sin_len = sizeof(zeroAddress);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    62
    zeroAddress.sin_family = AF_INET;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    63
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    64
    // Recover reachability flags
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    65
    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    66
    SCNetworkReachabilityFlags flags;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    67
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    68
    BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    69
    CFRelease(defaultRouteReachability);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    70
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    71
    if (!didRetrieveFlags) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    72
        NSLog(@"Error. Could not recover network reachability flags");
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    73
        return NO;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    74
    }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    75
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    76
    BOOL isReachable = flags & kSCNetworkFlagsReachable;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    77
    BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    78
    BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    79
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    80
    NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    81
    NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    82
    NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:self];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    83
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    84
    return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    85
}
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    86
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    87
@end
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    88
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    89
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    90
@implementation Appirater
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    91
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    92
+(void) appLaunched {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    93
    Appirater *appirater = [[Appirater alloc] init];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    94
    [NSThread detachNewThreadSelector:@selector(appLaunchedHandler) toTarget:appirater withObject:nil];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    95
}
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    96
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    97
-(void) appLaunchedHandler {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    98
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
    99
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   100
    if (APPIRATER_DEBUG) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   101
        [self performSelectorOnMainThread:@selector(showPrompt) withObject:nil waitUntilDone:NO];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   102
        return;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   103
    }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   104
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   105
    BOOL willShowPrompt = NO;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   106
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   107
    // get the app's version
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   108
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   109
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   110
    // get the version number that we've been tracking
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   111
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   112
    NSString *trackingVersion = [userDefaults stringForKey:kAppiraterCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   113
    if (trackingVersion == nil) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   114
        trackingVersion = version;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   115
        [userDefaults setObject:version forKey:kAppiraterCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   116
    }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   117
    
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   118
    if (APPIRATER_DEBUG)
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   119
        DLog(@"APPIRATER Tracking version: %@", trackingVersion);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   120
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   121
    if ([trackingVersion isEqualToString:version]) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   122
        // get the launch date
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   123
        NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterLaunchDate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   124
        if (timeInterval == 0) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   125
            timeInterval = [[NSDate date] timeIntervalSince1970];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   126
            [userDefaults setDouble:timeInterval forKey:kAppiraterLaunchDate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   127
        }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   128
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   129
        NSTimeInterval secondsSinceLaunch = [[NSDate date] timeIntervalSinceDate:[NSDate dateWithTimeIntervalSince1970:timeInterval]];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   130
        double secondsUntilPrompt = 60 * 60 * 24 * DAYS_UNTIL_PROMPT;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   131
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   132
        // get the launch count
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   133
        int launchCount = [userDefaults integerForKey:kAppiraterLaunchCount];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   134
        launchCount++;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   135
        [userDefaults setInteger:launchCount forKey:kAppiraterLaunchCount];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   136
        if (APPIRATER_DEBUG)
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   137
            NSLog(@"APPIRATER Launch count: %d", launchCount);
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   138
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   139
        // have they previously declined to rate this version of the app?
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   140
        BOOL declinedToRate = [userDefaults boolForKey:kAppiraterDeclinedToRate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   141
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   142
        // have they already rated the app?
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   143
        BOOL ratedApp = [userDefaults boolForKey:kAppiraterRatedCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   144
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   145
        if (secondsSinceLaunch > secondsUntilPrompt &&
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   146
             launchCount > LAUNCHES_UNTIL_PROMPT &&
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   147
             !declinedToRate &&
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   148
             !ratedApp) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   149
            if ([self connectedToNetwork]) {	// check if they can reach the app store
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   150
                willShowPrompt = YES;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   151
                [self performSelectorOnMainThread:@selector(showPrompt) withObject:nil waitUntilDone:NO];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   152
            }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   153
        }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   154
    } else {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   155
        // it's a new version of the app, so restart tracking
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   156
        [userDefaults setObject:version forKey:kAppiraterCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   157
        [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterLaunchDate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   158
        [userDefaults setInteger:1 forKey:kAppiraterLaunchCount];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   159
        [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   160
        [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   161
    }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   162
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   163
    [userDefaults synchronize];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   164
    if (!willShowPrompt)
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   165
        [self autorelease];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   166
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   167
    [pool release];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   168
}
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   169
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   170
-(void) showPrompt {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   171
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   172
                                                        message:APPIRATER_MESSAGE
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   173
                                                       delegate:self
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   174
                                              cancelButtonTitle:APPIRATER_CANCEL_BUTTON
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   175
                                              otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   176
    [alertView show];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   177
    [alertView release];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   178
}
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   179
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   180
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   181
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   182
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   183
    switch (buttonIndex) {
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   184
        case 0:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   185
            // they don't want to rate it
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   186
            [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   187
            break;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   188
        case 1:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   189
            // they want to rate it
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   190
            [[UIApplication sharedApplication] openURL:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   191
             [NSURL URLWithString:[templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", APPIRATER_APP_ID]]]];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   192
            
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   193
            [userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   194
            break;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   195
        case 2:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   196
            // remind them later
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   197
            break;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   198
        default:
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   199
            break;
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   200
    }
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   201
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   202
    [userDefaults synchronize];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   203
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   204
    [self release];
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   205
}
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   206
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents:
diff changeset
   207
@end