objective-c - StoreKit 委托(delegate)方法未被调用

标签 objective-c ios storekit

我有一个问题。永远不会调用 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/

相关文章:

iphone - void* 和 id 有什么区别?

iOS:第一次构建时加载 Images.xcassets 因为我有很多图像

ios - 使用 Xcode 7.1 的 iOS 9 中的 NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)

ios - 应用内购买收据中的 "expires_date"设置为早于 iOS 中的 "purchase_date"的日期

iOS 应用程序在恢复购买后提示用户使用密码 "Confirm Your In-App Purchase"

iphone - TableView 弹出框未解除 [self dismissPopoverAnimated :YES];

iphone - 弹出窗口内容 View 的额外高度

iOS:如何处理用户可选择的图标? (保存/加载等)

ios - 推送通知在 Apple Beta 测试 (TestFlight) 中不起作用

objective-c - 应用内购买 "Invalid Product Identifier"错误信息