我有一个我无法解决的问题,我被困住了。
我已经实现了一个应用程序内购买屏幕,问题是当我在 iOS3.1.3 上检查时,它在 iOS5 模拟器上也能完美运行,但在使用 iOS4 时我没有得到响应,
我正在使用的相关代码:
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
if ([response.products count]==0) {
// Always gets in here on iOS4....
}else{
//get here on 3.1.3 or 5
[productDetailsList addObjectsFromArray: response.products];
}
....
[request release];
}
- (void)requestProductData {
for (short item_count = 1; item_count <=4 ; item_count++) {
[productIdentifierList addObject:[NSString stringWithFormat:@"myApp.item.%d", item_count]];
}
SKProductsRequest *request = [[[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:productIdentifierList]] retain];
request.delegate = self;
[request start];
}
.h 文件如下所示:
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface viewController : UIViewController
<SKProductsRequestDelegate, SKPaymentTransactionObserver> {
NSMutableArray *productIdentifierList;
NSMutableArray *productDetailsList;
NSMutableArray *transactionHistory;
}
@property (nonatomic, retain) NSMutableArray *productIdentifierList;
@property (nonatomic, retain) NSMutableArray *productDetailsList;
@property (nonatomic, retain) NSMutableArray *transactionHistory;
- (void)requestProductData;
- (void)completeTransaction: (SKPaymentTransaction *)transaction;
- (void)restoreTransaction: (SKPaymentTransaction *)transaction;
- (void)failedTransaction: (SKPaymentTransaction *)transaction;
- (void)recordTransaction: (SKPaymentTransaction *)transaction;
- (void)provideContent: (NSString *)productIdentifier;
@end
我已经尝试从头开始进行所有配置,但并没有解决问题,也许这与内存管理有关,但我无法弄清楚是什么。
奇怪的是它在我的 3.1.3 上运行而不在 4.2.1 上运行。
请帮忙...
最佳答案
StoreKit API 在 4.2 中只能在 Device 上运行,因此您必须尝试在 Device 中执行它。 虽然在 3.1 ios 模拟器版本中我没有工作但在 ios5 模拟器中它正在工作我认为这可能是 ios5 模拟器的错误或者他们正在尝试提供新功能。 但在 Apple 的网站上,他们提到 storekit 只能在设备上运行。
所以您只需尝试在设备上构建您的项目。
关于iphone - 应用内购买适用于 iOS 3 和 5,但不适用于 iOS 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7946272/