iPhone编程中的应用内购买



我开发了一个应用程序。我有以下代码...在ViewController.m文件中,我调用了butoon1Clicked方法InAppPurchases。实际上,当第一次单击按钮时,我想执行应用内购买。如果事务成功,从下一个单击我想执行一些操作(例如,我给出了 NSLog 语句)我应该在哪里编写 NSLog stmt(或任何代码)来执行操作当我单击按钮后成功事务。请解释一下我必须写的地方。或者在任何过程中解释我。我想我想处理 BOOL 值,但我无法知道在哪里必须将 BOOL 值设置为 YES/NO。请解释一下...MyStoreObserver.m 文件执行应用内购买交易。

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;
}
我想

你参考这个链接,并实现代码...这个链接对我很有用...

购买产品时,您调用此函数:

 (void)productPurchased:(NSNotification *)notification

最新更新