我有一個9.0的iOS應用程序,我想添加應用內購買到; (我以前從未使用過IAP,並在網上找到一些代碼,希望能夠讓我開始使用)。我設置Category .h文件的方式有什麼問題?
我決定把代碼駐留在維護簡單類別(我只有過一次使用類別)。也就是說,我對該類別的實際結構存在問題。這是該類別中的.h文件中的代碼:
#import "SettingsViewController.h"
#import <StoreKit/StoreKit.h>
@interface SettingsViewController (Purchases)
@end
#define kInAppPurchaseManagerProductsFetchedNotification
@"kInAppPurchaseManagerProductsFetchedNotification"
@interface InAppPurchaseManager : NSObject <SKProductsRequestDelegate> {
SKProduct *proUpgradeProduct;
SKProductsRequest *productsRequest;
}
@end
這是.M代碼:
#import "SettingsViewController+Purchases.h"
@implementation SettingsViewController (Purchases)
- (void)requestProUpgradeProductData {
NSSet *productIdentifiers = [NSSet setWithObject:@"com.runmonster.runmonsterfree.upgradetopro" ];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
// we will release the request object in the delegate callback
}
#pragma mark -
#pragma mark SKProductsRequestDelegate methods
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;
if (proUpgradeProduct)
{
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
}
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(@"Invalid product id: %@" , invalidProductId);
}
// finally release the reqest we alloc/init’ed in requestProUpgradeProductData
[productsRequest release];
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}
@end
的問題是SKProduct和SKProductsRequest不可用的.m文件,這是我肯定是由我設置.h文件的方式造成的。幫助將不勝感激。
哪裏是實際的錯誤是什麼呢? – matt
另外,在這裏使用類別有什麼意義?這會給你帶來什麼? – matt
你的意思是'proUpgradeProduct'?是的,它看起來沒有定義。 – matt