【问题标题】:How to set up SandBox In-App Purchase in IOS如何在 IOS 中设置沙盒应用内购买
【发布时间】:2026-01-11 11:55:01
【问题描述】:

我为我的应用集成了应用内购买。我还在 iTunes 上设置了购买并将状态显示为Ready to Submit

但我想在不提交二进制文件的情况下对其进行测试。

那么,沙盒应用内测试还需要另外一套吗?

我的代码:

    [[SubclassInAppHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
        if (success)
        {
            [appDel dismissGlobalHUD];
            NSMutableArray *arrProductsBuyHeart = [[NSMutableArray alloc]init];
            NSMutableArray *arrTemp = [[NSMutableArray alloc]init];
            for (SKProduct *Sss in products)
            {
                NSString *string = Sss.productIdentifier;//@"hello bla bla";
                if ([string rangeOfString:@"com.xxxxxxxx.buy"].location == NSNotFound) {
                    //NSLog(@"string does not contain Buy");
                } else {
                    NSMutableDictionary *dictprod = [NSMutableDictionary dictionary];
                    [dictprod setObject:Sss.productIdentifier forKey:@"ProductIdentifier"];
                    [dictprod setObject:Sss.price forKey:@"ProductPrice"];
                    [dictprod setObject:Sss.localizedTitle forKey:@"ProductTitle"];
                    [arrTemp addObject:dictprod];
                }
            }
            if (arrTemp.count > 0)
            {
                NSSortDescriptor *brandDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ProductPrice" ascending:YES];
                NSArray *sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
                arrProductsBuyHeart = [NSMutableArray arrayWithArray:[arrTemp sortedArrayUsingDescriptors:sortDescriptors]];
                //NSLog(@"My products > %@",arrProductsBuyHeart);
                for (int i = 0;i<[arrProductsBuyHeart count];i++)
                {
                    NSString *strProductID = [[NSString stringWithFormat:@"%@",[[arrProductsBuyHeart objectAtIndex:i] objectForKey:@"ProductIdentifier"]]RemoveNull];
                    NSString *strPrice = [[NSString stringWithFormat:@"$%@",[[arrProductsBuyHeart objectAtIndex:i] objectForKey:@"ProductPrice"]]RemoveNull];
                    if ([strProductID isEqualToString:InApp200Coins])
                    {
                        [btn1KHeart setTitle:[NSString stringWithFormat:@"%@",strPrice] forState:UIControlStateNormal];
                    }
                    else if ([strProductID isEqualToString:InApp600Coins])
                    {
                        [btn2KHeart setTitle:[NSString stringWithFormat:@"%@",strPrice] forState:UIControlStateNormal];
                    }
                    else if ([strProductID isEqualToString:InApp900Coins])
                    {
                        [btn4KHeart setTitle:[NSString stringWithFormat:@"%@",strPrice] forState:UIControlStateNormal];
                    }
                    else if ([strProductID isEqualToString:InApp2KCoins])
                    {
                        [btn10KHeart setTitle:[NSString stringWithFormat:@"%@",strPrice] forState:UIControlStateNormal];
                    }
                    else if ([strProductID isEqualToString:InApp4KCoins])
                    {
                        [btn50KHeart setTitle:[NSString stringWithFormat:@"%@",strPrice] forState:UIControlStateNormal];
                    }
                }
            }
            else
                DisplayAlertWithTitle(@"Error Message", @"Unable to get product list or no in-app purchase found.");
        }
        else
        {
            [appDel dismissGlobalHUD];
            DisplayAlertWithTitle(@"Error Message", @"Unable to get product list or no in-app purchase found.");
        }
    }];
}

输出 DisplayAlertWithTitle(@"错误信息", @"无法获取产品列表或未找到应用内购买。"); & 无法获取产品列表。

帮我解决这个问题

【问题讨论】:

    标签: ios xcode in-app-purchase sandbox


    【解决方案1】:

    首先你可以在 iTunes Connect 中创建应用程序。

    -在应用内购买中添加产品。

    -然后在itunes主页之后你可以添加测试用户点击管理用户。

    添加后,您可以在设备中删除您的苹果帐户,然后使用测试用户登录

    登录后,您可以在沙盒模式下测试应用内购买。

    【讨论】:

    • 不,你可以在你的设备上测试。
    • 好的。非常感谢您的回答!过一段时间让我检查一下,如果有任何问题给你回电话,否则接受作为答案。
    • 它将在 ios6 模拟器上运行。但反应会有点慢。
    • 是网络问题。而您可以单击购买它从服务器获取您的产品详细信息。所以它需要一些时间。
    • 从iOS7开始无法在模拟器中测试In-Apps (:
    【解决方案2】:

    在 iTunes Connect 中创建一个测试用户帐户,如iTunes Connect Developer Guide 中的“创建测试用户帐户”中所述。

    在开发 iOS 设备上,在“设置”中退出 App Store。然后从 Xcode 构建并运行您的应用程序。

    在开发 OS X 设备上,退出 Mac App Store。然后在 Xcode 中构建您的应用程序并从 Finder 启动它。

    使用您的应用进行应用内购买。当系统提示您登录 App Store 时,请使用您的测试帐户。请注意,文本 “[Environment: Sandbox]” 会作为提示的一部分出现,表示您已连接到测试环境。

    如果没有出现“[Environment: Sandbox]”文字,则说明您使用的是生产环境。确保您正在运行应用程序的开发签名版本。生产签名的构建使用生产环境。

    重要提示:请勿使用您的测试用户帐户登录生产环境。否则,测试用户帐户将失效,无法再使用。

    【讨论】: