1

在 WWDC 2013 关于处理应用商店收据的演讲中,建议对于 iOS 应用,应尽快调用收据验证码。甚至之前application:didFinishLaunchingWithOptions:- 即在main()功能。我想它的工作方式如下:

int main(int argc, char *argv[]) {

    @autoreleasepool {
        validateReceiptMethod(); // <---- HERE
        int retVal = UIApplicationMain(argc, argv, nil, nil);
        return retVal;
    }
}

这个想法是该UIApplicationMain()方法是启动您的应用程序并调用application:didFinishLaunchingWithOptions:. 如果你把validateReceiptMethod()after UIApplciationMain(),它永远不会运行。

无论如何,这工作得很好。但是如果没有收据怎么办?然后你需要打电话SKReceiptRefreshRequest从应用商店获取一个新的,这很好。但是,如果您之前运行此代码UIApplciationMain(),它也会在您的任何 UI 显示之前运行。那么在向用户显示 Apple ID 登录对话框方面会发生什么?甚至可以SKReceiptRefreshRequestmain()方法中调用吗?

4

1 回答 1

2

那么在向用户显示 Apple ID 登录对话框方面会发生什么?

Store Kit 警报出现在不属于您的应用程序的窗口中,因此可以在您的应用程序不活动时显示 - 甚至在它启动之前。但这并不重要。

甚至可以SKReceiptRefreshRequestmain()方法中调用吗?

This may be possible if you set up your own event loop then stop it when the receipt request finishes, but you should not do this. Don’t delay launching your application waiting on a network request; it might never complete. If the receipt is invalid, I would recommend entering UIApplicationMain() and requesting another receipt when launching finishes.

Edit: Since you can not do anything about not having a valid receipt before entering UIApplicationMain(), I don’t understand why Apple recommends checking at this point. This makes sense on OS X as the application should terminate, but not on iOS where application should keep running and it is acceptable to ignore invalid receipts. You could check early, store the state in a global variable, then respond later; but why not check only when you’re ready to respond.

于 2013-12-05T18:57:46.603 回答