我有一个应用内购买应用。一切按设计工作...在应用程序购买工作,但我试图显示本地价格之前用户选择立即购买按钮。
目前,我的代码只会在启动流程后显示价格......
这是代码
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"IAP: Received Response");
// add wait text here
iAPnote.text = @"Connecting With App Store...";
SKProduct *validProduct = nil;
int count = [response.products count];
if (count>0) {
NSLog(@"IAP: Available, starting transaction");
validProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
// shows the cost of the in-app-purchase in the local currency (Canada / United States etc) using SKProduct+LocalizedPrice .h and .m helper files
[self.iAPprice setText:[NSString stringWithFormat:
@"Price: %@",validProduct.localizedPrice]];
} else {
NSLog(@"IAP: Item not found");
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Internet Connection Required"
message:@"You must connect to a Wi-Fi or cellular data network to perform an In-App Purchase."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
}
}
您会在第一个屏幕截图中注意到价格未显示...这是初始视图...一旦用户点击解锁按钮,则启动操作以查找价格,然后显示它...如何在没有用户启动过程的情况下实现此操作...如何在用户点击该按钮之前显示价格?
我需要启动viewDidLoad中的某些内容吗?