如何使用ios7中的产品设置付款中的产品

如何使用ios7中的产品设置付款中的产品,ios7,in-app-purchase,Ios7,In App Purchase,应用程序因错误而崩溃 [SKProduct productIdentifier]:发送到解除分配实例0x16d574f0的消息 在.h文件中 #import <Foundation/Foundation.h> #import <StoreKit/StoreKit.h> #define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotifica

应用程序因错误而崩溃

[SKProduct productIdentifier]:发送到解除分配实例0x16d574f0的消息

.h
文件中

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotification"
#define kInAppPurchaseManagerTransactionFailedNotification @"kInAppPurchaseManagerTransactionFailedNotification"
#define kInAppPurchaseManagerTransactionSucceededNotification @"kInAppPurchaseManagerTransactionSucceededNotification"
    @interface InAppPurchaseManager : NSObject <SKProductsRequestDelegate, SKPaymentTransactionObserver> {
    SKProduct *proUpgradeProduct;
    SKProductsRequest *productsRequest;

}
@property (retain, nonatomic) SKProduct *proUpgradeProduct;
@property (retain, nonatomic) SKProductsRequest *productsRequest;


// Public Methods
-(void)loadStore;
-(BOOL)canMakePurchases;
-(void)purchaseProUpgrade;
-(void)restorePurchases;
-(void)requestProUpgradeProductData;

@end
我的控制器代码

-(IBAction)buyUpgrade {

    [inAppPurchaseManager purchaseProUpgrade];

    // Add a notification observer to tell us when the purchase has been completed.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(purchaseComplete:) name:kInAppPurchaseManagerTransactionSucceededNotification object:nil];


}

-(void)purchaseComplete:(NSNotification *)notification {
    if ([[notification name] isEqualToString:kInAppPurchaseManagerTransactionSucceededNotification]) {
        NSLog(@"Purchase Successful!");
        // Notify user of successful purchase if desired
    }
}
并在控制器中加载存储

- (void)viewDidLoad
{
    [super viewDidLoad];

    inAppPurchaseManager = [[InAppPurchaseManager alloc] init];

    [inAppPurchaseManager loadStore];

    [inAppPurchaseManager canMakePurchases];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isProUpgradePurchased"]) {
        // Product has been purchased
        // Show premium options
        //
        //

    } else {
        // Product has not been purcahsed
        // Show free options
        //
        //
    }
    }
controller.h文件

@interface FirstViewController : UIViewController {

    InAppPurchaseManager *inAppPurchaseManager;


}

-(IBAction)buyUpgrade;

@end
日志文件

Relax[4469:60b] Loading Store
Relax[4469:60b] Getting Product
Relax[4469:60b] <Google> To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:@"fb34c5", nil];
Relax[4469:60b] Product title: Full Sounds Pack
Relax[4469:60b] Product description: The Full Sounds Pack includes all sounds, ads removal and every sound that will be added in the future
Relax[4469:60b] Product price: 1.79
Relax[4469:60b] <Google:HTML> Google Mobile Ads SDK: You are currently using 6.4.2 of the SDK. A new version, 6.8.0, is available at http://goo.gl/Zc0BYt . Please consider updating your SDK to get the latest features and bug fixes
Relax[4469:60b] *** -[SKProduct respondsToSelector:]: message sent to deallocated instance 0x145cec70
Relax[4469:60b]加载存储
放松[4469:60b]获取产品
Relax[4469:60b]要获取此设备上的测试广告,请调用:request.testDevices=[NSArray arrayWithObjects:@“fb34c5”,nil];
放松[4469:60b]产品名称:全套声音套装
Relax[4469:60b]产品说明:完整的声音包包括所有声音、删除广告以及将来添加的所有声音
放松[4469:60b]产品价格:1.79
放松[4469:60b]谷歌移动广告SDK:您目前正在使用SDK的6.4.2。新版本6.8.0可从以下网址获得:http://goo.gl/Zc0BYt . 请考虑更新SDK以获得最新的特性和bug修复。
Relax[4469:60b]***-[SKProduct respondsToSelector:]:消息发送到解除分配的实例0x145cec70
proupgrade产品的问题在哪里?
为空???

您正在使用此代码吗

您的Proupgrade产品似乎正在被出售。我看不出是怎么回事。我会清理一些代码来简化。例如,我将去掉proUpgradeProduct和productsRequest属性(或实例变量)。我还想摆脱这一行:

proUpgradeProduct=[[SKProduct alloc]init]自动释放]

在接管人的回复中。它没有做任何有用的事


当您对代码进行更改时,请确保将更改的方法完全复制到发布的代码中。

行中proUpgradeProduct为null时的问题

proUpgradeProduct = [products count] == 1 ? [products firstObject]: nil;
我意识到一定是这样的

proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain]: nil;

您能给出程序生成的日志输出吗?***-[SKProduct productIdentifier]:发送到解除分配实例0x15DEB470的消息,因此,听起来好像没有调用didReceiveResponse。请在SKPayment*payment=[SKPayment paymentWithProduct:proUpgradeProduct]行之前显示proUpgradeProduct的值,好吗?也就是说,放置一个NSLog(@“%@”,proUpgradeProduct);在该行之前。在日志行日志中添加日志和chrash应用程序:-[SKProduct respondsToSelector:]:消息发送到解除分配的实例0x155D75C0我很难理解您。请编辑您的原始帖子以显示修改后的代码,以及我建议的日志消息。在post viewcontroller.h文件中添加。
proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain]: nil;