【问题标题】:In App Purchases in iPhone ProgrammingiPhone 编程中的应用内购买
【发布时间】:2012-05-18 15:56:00
【问题描述】:

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

【问题讨论】:

  • 没有人会阅读那堵代码墙。将您的问题简化为更易于理解的内容。
  • 是的,马克是对的。您至少应该找出问题或发现问题的小部分。
  • 我已经减少了代码...现在请看我的问题一次...

标签: iphone objective-c ios5 xcode4.2 in-app-purchase


【解决方案1】:

我认为you refer this link,并实现代码...这个链接对我有用...

购买产品时调用此函数:

 (void)productPurchased:(NSNotification *)notification

【讨论】:

  • @elpaa...我已经使用该链接完成了我的编码...我的 InAPP 购买交易工作正常...只是简单的事情...我不知道我应该去哪里在我的应用程序中编写代码以在成功事务后单击按钮时执行操作...
  • 如果您使用的是链接码,请使用此函数 (void)productPurchased:(NSNotification *)notification in .m 文件,您的产品购买成功后调用此函数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-07
  • 1970-01-01
相关资源
最近更新 更多