设置测试应用程序和应用内购买测试项目 我在 iPhone Dev Centre 的公司开发者门户网站上为“Test App One”创建了一个新的应用程序 ID。我确保前缀是 com.mycompany.testappone,以确保可以配置应用内购买。在应用程序 ID 部分停留时,我通过选中“启用应用内购买”选项来配置应用内购买。
我在 iTunes Connect 中创建了“Test App One”,并完成了通常的程序,但选择了“稍后上传二进制文件”,并且没有提交审核,因为该应用程序什么都不做。我们肯定不必提交应用程序进行审核才能使其工作吧?然后,我单击管理应用内购买,并创建了一个新的产品 ID 为“test1”的产品,并批准了它,以便可以出售。
代码 我在 XCode 中设置了一个名为 TestAppOne 的新项目,现在这里是我正在使用的唯一 2 个类:
TestAppOneAppDelegate.h:
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface TestAppOneAppDelegate : NSObject <UIApplicationDelegate, SKRequestDelegate, SKProductsRequestDelegate> {
UIWindow *window;
}
TestAppOneDelegate.m:
#import "TestAppOneAppDelegate.h"
static NSString *kMyFeatureIdentifier1 = @"com.mycompany.testappone.test1";
@implementation TestAppOneAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
if([SKPaymentQueue canMakePayments]) {
NSLog(@"IN-APP:can make payments");
}
else {
NSLog(@"IN-APP:can't make payments");
}
[self requestProductData];
[window makeKeyAndVisible];
}
- (void)requestProductData {
NSLog(@"IN-APP:requestProductData");
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:kMyFeatureIdentifier1]];
request.delegate = self;
[request start];
NSLog(@"IN-APP:requestProductData END");
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(@"IN-APP:productsRequest");
NSArray *myProduct = response.products;
NSLog(@"IN-APP:array count: %i", [myProduct count]);
[request autorelease];
NSLog(@"IN-APP:productsRequest END");
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
在设备上进行测试
我创建了一个沙盒测试账号,并从iPhone上注销了我的iTunes账号,但没有像文档所告诉我们的那样,在购买阶段提示之前登录测试账号。然后我构建了应用程序,这是我得到的日志:
IN-APP:can make payments
IN-APP:requestProductData
IN-APP:requestProductData END
IN-APP:productsRequest
IN-APP:array count: 0
IN-APP:productsRequest END
请问我是否遗漏了任何步骤或者做错了什么。不幸的是,苹果并没有提供任何示例应用程序。