我开发了一个应用程序购买应用程序。我有以下代码...在ViewController.m文件中我是butoon1Clicked方法我是callInAppPurchases。实际上,当我第一次点击按钮时,我想进行In App Purchases。如果事务成功,从下一次单击我想要执行某些操作(例如我给出NSLog语句)我应该在程序中编写NSLog stmt(或任何代码)以便在我单击时执行Action成功交易后的按钮。请在我必须写的地方冒险。或者在任何过程中解释我。我以为我想处理BOOL值,但我不知道我必须将BOOL值设置为YES / NO。请解释一下...... MyStoreObserver.m文件执行In App Purchase Transactions。
ViewController.m
-(IBAction)button1Clicked:(id)sender
{
[self callInAppPurchase];
NSLoG(@"Perform Some Action");
}
#pragma mark-In-AppPurchase code from here
-(void)callInAppPurchase
{
if ([SKPaymentQueue canMakePayments])
{
// Display a store to the user.
}
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import "MyStoreAbserver.h"
@interface iTeach_MathsAppDelegate : NSObject <UIApplicationDelegate>
{
BOOL isPurchased,isFailed;
}
@property (nonatomic, readwrite) BOOL isPurchased,isFailed;
@property (nonatomic, retain) IBOutlet UIWindow *window;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
MyStoreAbserver *observer = [[MyStoreAbserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"isPurchased"] isEqualToString:@"true"])
self.isPurchased = YES;
else
isPurchased = NO;
isFailed = NO;
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
答案 0 :(得分:0)
我认为you refer this link,并实现代码......此链接对我有用...
购买产品时,您可以调用此功能:
(void)productPurchased:(NSNotification *)notification