Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Iphone 应用内购买响应从未出现_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 应用内购买响应从未出现

Iphone 应用内购买响应从未出现,iphone,objective-c,ios,Iphone,Objective C,Ios,在我的iPhone应用程序中,我设置了应用程序内购买。我以如下方式启动请求: SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.nicknoble.tiprounder.upgrade"]]; request.delegate = self; [request start]; 我用这个方法得到了答案: - (void)pro

在我的iPhone应用程序中,我设置了应用程序内购买。我以如下方式启动请求:

SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.nicknoble.tiprounder.upgrade"]];
request.delegate = self;
[request start];
我用这个方法得到了答案:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{   
    NSLog(@"response recieved");
}
这一个用来捕捉错误:

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"%@",error.description);
}
但两人都没有接到电话。我的项目没有警告或错误,我正在我的设备(iPhone)上运行。有什么建议吗

编辑:

因此,它可以在我的窗口的根视图控制器上工作,但不能在我提供的模态视图控制器上工作。以下是我的主视图控制器中的代码:

TestViewController *testView = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
[self presentModalViewController:testView animated:YES];
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>

@interface TestViewController : UIViewController <SKProductsRequestDelegate>
@end
以下是TestViewController的.h文件:

TestViewController *testView = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
[self presentModalViewController:testView animated:YES];
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>

@interface TestViewController : UIViewController <SKProductsRequestDelegate>
@end

我绝望了。任何帮助都会很好!谢谢

首先检查您的产品标识符。
还要检查实现这些方法的类是否没有以某种方式发布。(可能会自动释放并在您等待响应时自动释放)

首先检查您的产品标识符。
还要检查实现这些方法的类是否没有以某种方式发布。(可能会自动释放并在您等待响应时自动释放)

需要在请求期间保留
SKProductsRequest
实例。如果没有,它将安静地死去(不通知其委托人),因为没有其他东西保留它

现在,只要代码退出您分配它的范围,ARC就会立即删除您的
SKProductsRequest

解决方案是将您的
SKProductsRequest
保存在ivar中,并在请求完成/失败时将其设置为
nil
。这也有助于防止在已有请求正在进行时启动请求:

// Define _productsRequest as an ivar of type SKProductsRequest in your class

- (void)someMethodThatInitiatesTheProductsRequest
{
    if( _productsRequest != nil )
        return; // There's already a request in progress. Don't start another one.

    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.nicknoble.tiprounder.upgrade"]];
    request.delegate = self;
    [request start];

    _productsRequest = request; // <<<--- This will retain the request object
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{   
    NSLog(@"response recieved");
    _productsRequest = nil; // <<<--- This will release the request object
}

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"%@",error.description);
    _productsRequest = nil; // <<<--- This will release the request object
}
//将_productsRequest定义为类中SKProductsRequest类型的ivar
-(无效)启动产品请求的某些方法
{
如果(_productsRequest!=nil)
return;//已经有一个请求在进行中。不要启动另一个请求。
SKProductsRequest*请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@“com.nicknoble.tiprounder.upgrade”];
request.delegate=self;
[请求启动];

_productsRequest=request;//需要在请求期间保留
SKProductsRequest
实例。如果不保留,它将无声地死去(不通知其委托人),因为没有其他东西在保留它

现在,只要代码退出您分配它的范围,ARC就会立即删除您的
SKProductsRequest

一种解决方案是将您的
SKProductsRequest
保存在ivar中,并在请求完成/失败时将其设置为
nil
。这也有助于防止在已有请求进行时启动请求:

// Define _productsRequest as an ivar of type SKProductsRequest in your class

- (void)someMethodThatInitiatesTheProductsRequest
{
    if( _productsRequest != nil )
        return; // There's already a request in progress. Don't start another one.

    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.nicknoble.tiprounder.upgrade"]];
    request.delegate = self;
    [request start];

    _productsRequest = request; // <<<--- This will retain the request object
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{   
    NSLog(@"response recieved");
    _productsRequest = nil; // <<<--- This will release the request object
}

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"%@",error.description);
    _productsRequest = nil; // <<<--- This will release the request object
}
//将_productsRequest定义为类中SKProductsRequest类型的ivar
-(无效)启动产品请求的某些方法
{
如果(_productsRequest!=nil)
return;//已经有一个请求在进行中。不要启动另一个请求。
SKProductsRequest*请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@“com.nicknoble.tiprounder.upgrade”];
request.delegate=self;
[请求启动];

_productsRequest=request;//产品标识符完全匹配,我使用的是ARC。我的代码中没有任何发布或自动删除。我以为这是我项目中唯一与此相关的代码。你能更具体地说明什么可能有用吗?好吧,现在我的心都碎了。我只是将此代码复制并粘贴到另一个viewController中…它rks在那里。发生了什么。产品标识符完全匹配,我使用ARC。我的代码中没有任何发布或自动删除。我认为这是我项目中唯一与此相关的代码。你能更具体地说明什么可能有用吗?好吧,现在我的脑子被炸开了。我只是将此代码复制并粘贴到另一个viewController中…它可以工作了好了。发生了什么事。+1但您不需要保留辩论而不是请求,因为它应该接收调用,而请求也不会保留它(它的属性定义使用assign而不是strong).+1但您是否必须保留辩论而不是请求,因为它应该接收调用,而请求也不会保留它(其属性定义使用assign而不是strong)。