Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
//  InfoVC.m
//  Foresta
//
//  Created by Fabrizio on 18/12/12.
//  Copyright (c) 2012 Odyssey. All rights reserved.
//

#import "InfoVC.h"

@interface InfoVC ()

@end

@implementation InfoVC

@synthesize version;
@synthesize titleLabel;
@synthesize inappObserver;
@synthesize donateBtn;
@synthesize activityIndicator;
@synthesize backBtn;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    
    if(!DATAMANAGER.purchased) {
        inappObserver = [[InAppPurchaseObserver alloc] init];
        
        if ([SKPaymentQueue canMakePayments]) {
            // Yes, In-App Purchase is enabled on this device!
            // Proceed to fetch available In-App Purchase items.
            
            // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID,
            // fetched from either a remote server or stored locally within your app.
            [activityIndicator startAnimating];
            
            SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"RemoveADV"]];
            prodRequest.delegate = self;
            [prodRequest start];
            
        } else {
            // Notify user that In-App Purchase is disabled via button text.
            donateBtn.enabled = NO;
        }
    }
    
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(purchasing) name:@"purchasing" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentComplete) name:@"paymentComplete" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentFailed) name:@"paymentFailed" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentRestored) name:@"paymentRestored" object:nil];
       
    titleLabel.text = APP_NAME;
	version.text = [NSString stringWithFormat:@"v. %@", APP_VERSION];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void) purchasing {
    [activityIndicator startAnimating];
    backBtn.enabled = NO;
}

- (void) paymentComplete {
    [activityIndicator stopAnimating];
    // Your application should implement these two methods.
//    [self recordTransaction:transaction];
    DATAMANAGER.purchased = YES;
    [DATAMANAGER savePurchase];
    
    backBtn.enabled = YES;
    
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Pagamento avvenuto con successo" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [myAlertView show];
}

- (void) paymentFailed {
    [activityIndicator stopAnimating];
    
    DATAMANAGER.purchased = NO;
    [DATAMANAGER savePurchase];
    
    backBtn.enabled = YES;
    
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Pagamento non avvenuto, ritenta" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [myAlertView show];
}

- (void) paymentRestored {
    [activityIndicator stopAnimating];
    
    DATAMANAGER.purchased = YES;
    [DATAMANAGER savePurchase];
    
    backBtn.enabled = YES;
    
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Pagamento avvenuto con successo" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [myAlertView show];
}

#pragma mark -
#pragma mark IBActions

- (IBAction) donate {
        
    // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID.
	SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"RemoveADV"];
    
	// Assign an Observer class to the SKPaymentTransactionObserver,
	// so that it can monitor the transaction status.
	[[SKPaymentQueue defaultQueue] addTransactionObserver:inappObserver];
	
	// Request a purchase of the selected item.
	[[SKPaymentQueue defaultQueue] addPayment:paymentRequest];
}

- (IBAction) close {
	[self dismissModalViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark Store Kit
// Store Kit returns a response from an SKProductsRequest.
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    
    [activityIndicator stopAnimating];
    
	// Populate the inappBuy button with the received product info.
	SKProduct *validProduct = nil;
	int count = [response.products count];
	if (count>0) {
		validProduct = [response.products objectAtIndex:0];
	}
	if (!validProduct) {
		donateBtn.enabled = NO;
		return;
	}
	
	donateBtn.enabled = YES;
}



@end

Commits for Nextrek/iOS/Foresta/Foresta/InfoVC.m

Diff revisions: vs.
Revision Author Commited Message
64 FAquili picture FAquili Sat 18 Jan, 2014 18:22:40 +0000

Foresta