我对恢复购买的正确/最佳措辞感兴趣。
我已经看到了足够多的“未知错误”警报,只需在 -(void)paymentQueue:restoreCompletedTransactionsFailedWithError: 中使用 [error localizedDescription]。 (待办事项:填充雷达)
所以我看了一下 Apple 是如何做到的。目前,Apple 推出的唯一具有非消耗性应用内购买的应用是 GarageBand(2014 年 12 月)。
而不是“恢复购买”、“恢复以前的购买”或......它们与"Already Purchased?" 一起使用。
但是这里是我比较感兴趣的画面,在没有什么可以恢复的时候按"Already Purchased?"的结果:
"There are no items available to restore at this time." 不是革命性的,但从“未知错误”中击败了地狱
让我们看看-(void)paymentQueue:restoreCompletedTransactionsFailedWithError:。
iOS:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
if ([error.domain isEqual:SKErrorDomain] && error.code == SKErrorPaymentCancelled)
{
return;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"There are no items available to restore at this time.", @"")
message:nil
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
}
OS X:
我对 OS X 上的相同文本不满意。只有 messageText 而没有 informationativeText 的 NSAlert 看起来是空的和错误的。
我的一个选择是让用户知道他需要购买它,例如"To use it, you need to buy “%@”."。
我想出的另一个选择是让他们在那里浏览Purchase History。我发现你可以直接用itms://phobos.apple.com/purchaseHistory链接到它。老实说,iTunes Store 中的购买历史是一坨屎,它会让你永远找到一些东西。
但也许它有助于向人们重新保证我们不会试图让他们重新购买某些东西。始终假设您的客户不知道或无法区分非消耗品和消耗品之间的区别。而且不知道他们不能为非消耗品收取两次费用。
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
if ([error.domain isEqual:SKErrorDomain] && error.code == SKErrorPaymentCancelled)
{
return;
}
NSAlert *alert = nil;
alert = [NSAlert alertWithMessageText:NSLocalizedString(@"There are no items available to restore at this time.", @"")
defaultButton:NSLocalizedString(@"OK", @"")
alternateButton:NSLocalizedString(@"Purchase History", @"")
otherButton:nil
informativeTextWithFormat:@"You can see your purchase history in the iTunes Store."];
NSModalResponse returnCode = [alert runModal];
if (returnCode == NSAlertAlternateReturn)
{
NSURL *purchaseHistory = [NSURL URLWithString:@"itms://phobos.apple.com/purchaseHistory"];
[[NSWorkspace sharedWorkspace] openURL:purchaseHistory];
}
}
OS X 上的示例
测试说明(OS X,itunesconnect 沙盒用户):
当用户点击取消时:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
Error Domain=SKErrorDomain Code=2 "The payment was canceled by the user" UserInfo=0x600000470a40 {NSLocalizedDescription=The payment was canceled by the user}
当没有什么可以恢复时:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
Error Domain=SKErrorDomain Code=0 "Unknown Error." UserInfo=0x60800007fb80 {NSLocalizedDescription=Unknown Error.}