admin管理员组文章数量:1657155
本文是 adat 项目的第二篇。主要内容是对 iOS 和 macOS 应用内购相关的释疑,包括各种问题出现的原因、如何解决以及最佳实践等。作者还结合亲身经历,给开发者、运营者提供了一些实用建议。
内容概览
- 配置
- 错误信息
- 本地化
- 票据
- 订阅
- 其他问题
配置
必须要上传 App 才能测试应用内购买吗?
不需要。测试内购不要求上传 App。在App Store Connect
创建好商品并确保没有问题,就可以测试内购了。
注意,不要将未开发完成的测试包上传至 App Store Connect 并提审,因为它很大概率会被拒审。如果审核被拒,内购商品将会被置为不可用,测试内购一定会失败,记得再次测试前修改商品变为可用。
推荐做法是:在 App 其他功能基本完成后,先提交一个不含内购功能的 App,待审核通过后,再把内购项加上,再提交一次审核。这样做的好处是:如果有问题,大部分已经在第一次审核的时候就暴露出来了,并且有充足的时间修改。最后的一次提交审核,基本只是审核内购项,会快很多。
如何帮助 Apple 打击购买期间的欺诈行为?
SKPayment
提供了一个applicationUsername
属性,它可以帮助 Apple 识别请求购买时的异常活动。它的值最好是服务器生成的用户标识符的单向哈希值。创建交易对象后,将该哈希值设置为 applicationUsername 属性的值,然后再添加到交易队列SKPaymentQueue
。
注意,不要用开发者账号的 Apple ID、用户的 Apple ID 或未哈希的用户标识符来填充 applicationUsername。
下面提供了一个示例方法来创建哈希值,以用户标识为参数,返回值是用户标识的SHA-256
值:
// Custom method to calculate the SHA-256 hash using Common Crypto.
- (NSString *)hashedValueForAccountName:(NSString *)userAccountName {
const int HASH_SIZE = 32;
unsigned char hashedChars[HASH_SIZE];
const char *accountName = [userAccountName UTF8String];
size_t accountNameLen = strlen(accountName);
// Confirm that the length of the user name is small enough
// to be recast when calling the hash function.
if (accountNameLen > UINT32_MAX) {
NSLog(@"Account name too long to hash: %@", userAccountName);
return nil;
}
CC_SHA256(accountName, (CC_LONG)accountNameLen, hashedChars);
// Convert the array of bytes into a string showing its hex representation.
NSMutableString *userAccountHash = [[NSMutableString alloc] init];
for (int i = 0; i < HASH_SIZE; i++) {
// Add a dash every four bytes, for readability.
if (i != 0 && i%4 == 0) {
[userAccountHash appendString:@"-"];
}
[userAccountHash appendFormat:@"%02x", hashedChars[i]];
}
return userAccountHash;
}
将方法返回结果填充到SKMutablePayment
对象的 applicationUsername 属性:
// product is an SKProduct object.
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
//Populate applicationUsername with your customer's username on your server.
payment.applicationUsername = [self hashedValueForAccountName:@"userNameOnYourServer"];
// Submit payment request.
[[SKPaymentQueue defaultQueue] addPayment:payment];
支持自动续期订阅的最低版本。
目前自动续期订阅
(Auto-renewable Subscriptions)只支持 iOS 和 macOS 平台,最低版本分别是iOS 4.2
和macOS 10.9
。
什么时候使用 restoreCompletedTransactions 方法?
该方法只能用于自动续期订阅和非消耗型产品,使用场景如下:
- 用户在一台设备上订阅后,换了其他设备,在新设备上需要恢复交易。
- 用户卸载重装了
版权声明:本文标题:TN2413: 应用内购(In-App Purchase)常见问题 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729772136a1212376.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论