我在 App Purchases 中开发了一个应用程序。我有以下代码...在 ViewController.m 文件中,我调用了名为 InAppPurchases 的 butoon1Clicked 方法。实际上,当我第一次单击按钮时,我想执行应用内购买。如果交易成功,从下一次单击我想执行一些操作(例如,我给出了 NSLog 语句)我应该在哪里编写程序中的 NSLog stmt(或任何代码)以执行操作交易成功后的按钮。请解释我必须在哪里写。或在任何过程中向我解释。我以为我想处理 BOOL 值,但我不知道我必须在哪里将 BOOL 值设置为 YES / NO。请解释一下... MyStoreObserver.m 文件执行应用内购买交易。
视图控制器.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;
}