Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用内购买-最后阶段帮助-下载内容_Ios_Objective C_Xcode_In App Purchase_Storekit - Fatal编程技术网

Ios 应用内购买-最后阶段帮助-下载内容

Ios 应用内购买-最后阶段帮助-下载内容,ios,objective-c,xcode,in-app-purchase,storekit,Ios,Objective C,Xcode,In App Purchase,Storekit,我已经在我的应用程序中实现了IAP,但是我在计算用户付费后应该在哪里找到购买的内容时遇到了问题 使用我的测试帐户,当我单击“购买”按钮时,它会在IAP上打勾,似乎表示它已购买,但从那里我找不到内容 是否有人可以帮助我向代码和情节提要添加什么内容,以便用户能够访问他们购买的内容。。。。(内容将是通过IAP向用户提供的几个短视频) 通过阅读所有教程,我认为我缺少的代码是: -(void)paymentQueueSKPaymentQueue *)queue updatedDownloadsNSArra

我已经在我的应用程序中实现了IAP,但是我在计算用户付费后应该在哪里找到购买的内容时遇到了问题

使用我的测试帐户,当我单击“购买”按钮时,它会在IAP上打勾,似乎表示它已购买,但从那里我找不到内容

是否有人可以帮助我向代码和情节提要添加什么内容,以便用户能够访问他们购买的内容。。。。(内容将是通过IAP向用户提供的几个短视频)

通过阅读所有教程,我认为我缺少的代码是:

-(void)paymentQueueSKPaymentQueue *)queue updatedDownloadsNSArray *)downloads
{
    for (SKDownload *download in downloads)
    {
        switch (download.downloadState) {
            case SKDownloadStateActive:
                NSLog(@"Download progress = %f", 
                download.progress);
                NSLog(@"Download time = %f", 
                download.timeRemaining);
            break;
            case SKDownloadStateFinished:
                // Download is complete. Content file URL is at 
                // path referenced by download.contentURL. Move 
                // it somewhere safe, unpack it and give the user 
                // access to it
            break;
            default:
            break;
        }
    }
}

但是,我还需要一种方法将完成的下载传输回应用程序,然后将视图控制器链接到这些下载/购买的内容(我该怎么做?

以下是我的一个应用程序中的一些示例代码,希望对您有所帮助。基本上,您需要做的是确定所购买产品的索引,然后根据该索引提供内容。如果您只有一次应用内购买,那么您只需在购买通知后提供内容即可

- (void)productPurchased:(NSNotification *)notification {

    [self makeSuccessAlert];

    NSString * productIdentifier = notification.object;
    [_products enumerateObjectsUsingBlock:^(SKProduct * product, NSUInteger idx, BOOL *stop) {
        if ([product.productIdentifier isEqualToString:productIdentifier]) {
            if (idx == 0) {
                coins = [NSNumber numberWithInteger:[coins integerValue] + 5000];
                NSLog(@"coins %d", [coins integerValue]);
                [totalCoins setString:[NSString stringWithFormat:@"%d", coins.integerValue]];
                [[NSUserDefaults standardUserDefaults] setObject:coins forKey:@"coins"];
                [[NSUserDefaults standardUserDefaults] synchronize];

            }
            if (idx == 1) {
                coins = [NSNumber numberWithInteger:[coins integerValue] + 15000];
                NSLog(@"coins %d", [coins integerValue]);
                [totalCoins setString:[NSString stringWithFormat:@"%d", coins.integerValue]];
                [[NSUserDefaults standardUserDefaults] setObject:coins forKey:@"coins"];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }

            *stop = YES;
        }
    }];
}

我已经有了这个方法,我的IAP是非消耗品,你的是硬币,所以是消耗品。但是,这本身无法解决此问题,因为我需要能够“下载项目”,然后从下载目录中获取项目,然后返回到应用程序中,并允许用户查看其购买的内容。您是否解决了此问题?当然,除了这个方法之外,还需要将类设置为观察者,否则该方法永远不会被调用。到目前为止,我只从测试服务器下载过一次(仍然没有发现问题是苹果服务器还是我的代码)。我得到的是一个zip文件,我打开它作为一个目录。然后,我就可以像阅读普通文件一样阅读这些内容,并将它们适当地写在其他地方。