我有一个问题。永远不会调用 SKProductsRequest 委托(delegate)方法。之前有人问过这个问题,但没有答案。 StoreKit delegate functions are not getting called
我的母语不是英语,我有时听起来可能很有趣 :P :(
我想在我的 iOS 应用中实现 StoreKit。我制作了一个类来处理所有 StoreKit 通信。这是代码:
@implementation VRStoreController
- (void) requestProducts
{
SKProductsRequest *request= [[SKProductsRequest alloc]
initWithProductIdentifiers:
[NSSet setWithObject: @"myProductID"]];
request.delegate = self;
[request start];
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
}
- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"F7U12");
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
NSArray *myProducts = response.products;
NSLog(@"%@", myProducts);
}
我在我的应用委托(delegate)中创建了一个实例
@interface VRAppDelegate
@property (strong, nonatomic) VRStoreController *store;
@end
奇怪的是,当我在我的 appDidFinishLaunching: 方法中运行 [store requestProducts] 时,这段代码工作正常。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//app initialization...
self.store = [[VRStoreController alloc]init];
[store requestProducts]; //This works ok, delegate method gets called.
return YES;
}
但是当我在设置 tableView:didSelectRowAtIndexPath 中运行代码时:永远不会调用委托(delegate)方法。
//VRAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//app initialization...
self.store = [[VRStoreController alloc]init];//initialize store
return YES;
}
//VRSettingsViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
//case 0, 1...
case 2:
{
VRStoreController *store = ((VRAppDelegate *)[UIApplication sharedApplication].delegate).store;
[store requestProducts]; //calls SKProductRequest start, but never calls delegate method.
NSLog(@"GO PRO");
}
default:
break;
}
}
我不知道我做错了什么。尝试了几乎所有的东西,没有错误,没有崩溃,但是永远不会调用委托(delegate)。任何帮助将不胜感激。
提前致谢!
最佳答案
SKProductsRequestDelegate
协议(protocol)也符合SKRequestDelegate
协议(protocol),有如下方法:
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
- (void)requestDidFinish:(SKRequest *)request;
实现它们并查看它们中的任何一个是否被调用。您可能收到错误或其他意外响应。
关于objective-c - StoreKit 委托(delegate)方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9935054/