如何开始编写应用程序内购买

时间:2010-01-28 05:47:40

标签: iphone objective-c

我正在进行应用内购买。在我的应用程序中,我们在appdelegate中添加了以下代码:

    #import "InappPurchaseAppDelegate.h"
    #import "MainController.h"
    #import "MKStoreManager.h"
    #import "MKStoreObserver.h"

    @implementation InappPurchaseAppDelegate

    @synthesize window;


    - (void)applicationDidFinishLaunching:(UIApplication *)application 
    { 
      [MKStoreManager sharedManager];


      navigationController = [[UINavigationController alloc] init];
      [window addSubview:navigationController.view];
      MainController *frontController =[[MainController alloc] init];
      [navigationController pushViewController:frontController animated:NO ];
      [frontController release];    // Override point for customization after      application launch
      [window makeKeyAndVisible];
    }

并在我们的控制器中添加了以下代码:

    #import "MainController.h"
    #import "MKStoreManager.h"
    #import "MKStoreObserver.h"

    #import "InappPurchaseAppDelegate.h"


    @implementation MainController


    -(IBAction)InappPurchase:(id)sender
    {
      [[MKStoreManager sharedManager] buyFeatureA];

    }

我还添加了storekit框架,但是当点击按钮时没有任何反应。

2 个答案:

答案 0 :(得分:1)

您需要知道的只有:http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Overview%20of%20the%20Store%20Kit%20API/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1

实施它不应该超过半天(如果内容驻留在您的服务器上并且尚未包含在捆绑中,可能会多一点)。

答案 1 :(得分:0)

最简单的解释是您的按钮未正确配置为发送操作消息。要测试是为方法设置断点还是记录它:

-(IBAction)InappPurchase:(id)sender
  {
     NSLog(@"Buyid method called");
     [[MKStoreManager sharedManager] buyFeatureA]; 
  }

如果永远不会命中NSLog或断点,则需要检查Interface Builder中的按钮,并将其操作设置为InappPurchase方法。

如果按钮调用InappPurchase方法,则问题出在MKStoreManger对象中。