如何在iOS模拟器或设备上testingIAP(应用内购买)?
遵循Ray Wenderlich教程手册,我实现了一个简单的非易耗品应用内购买机制。
当我的应用程序启动时,我发起一个产品信息请求:
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers]; _productsRequest.delegate = self; [_productsRequest start];
SKProductRequest被创build。 它有一个内存地址,但没有其他事情发生。 没有一个委托方法被调用:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSLog(@"Product info received..."); NSArray *products = response.products; for (SKProduct *product in products) { NSLog(@"ID: %@, title:%@, (%f)", product.productIdentifier, product.localizedTitle, product.price.floatValue); } self.productsRequest = nil; } - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { NSLog(@"Failed to load list of products"); self.productsRequest = nil; }
我检查了两次:
- 应用程序完全在iTunes Connect中设置。
- ITC应用程序的状态是“准备上传”
- 添加了一个非易损件IAP。
- ITC产品在ITC中的状态是“准备提交”
- 应用程序ID是com.mycompany.myapp,既适用于应用程序,也适用于plist。 检查两次。
- IAP使用com.mycompany.myapp.productname(对请求使用完全相同的ID)。
- 在ITC中创build一个testing用户帐户。
- 还没有提交给苹果呢。
- 我的Mac有互联网接入。
- 控制台或屏幕上没有其他消息。
Ray Wenderlich的书没有提到我除了这个之外还必须做其他事情。
只有一次,我看到一个-didFailWithError:调用我的代理在设备上,但它再也没有出现过。 我的委托不会被设备或模拟器调用。 我让它跑了几分钟,根本没有任何反应。
iTunes Connect提供了这个令人困惑的警告:
您的第一次应用程序内购买必须提交一个新的应用程序版本。 从“版本详细信息”页面的“应用程序内购买”部分select它们,然后单击“准备好上传二进制文件”。
这需要能够testing应用程序内购买?
在当前版本的Xcode 5.0(5A1413)中,应用内购买将无法在iOS模拟器中运行。
StoreKit(应用内购买)在模拟器中不起作用。 13962338
来源:Xcode 5.0发行说明>已知问题> iOS模拟器https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/xc5_release_notes/xc5_release_notes.html#//apple_ref/doc/uid/TP40001051- CH2-SW303
在iOS模拟器文档中,它被写成:
API限制
在iOS模拟器中,API和function有一些限制,包括:
Apple Push Services Privacy alerts for access to Photos, Contacts, Calendar, and Reminders The UIBackgroundModes key iCloud document syncing and key-value storage support
不受支持的框架包括:
External Accessory Media Player Message UI Event Kit In UIKit, the UIVideoEditorController class Store Kit
由于应用内购买需要Store Kit正常工作,并且Simulator不支持Store Kit框架,因此无法在iOS模拟器中testingIAP。
更多信息: iOS模拟器文档
不幸的是有几件事你不能在模拟器上testing。 应用内购买属于该列表。
所以你不能在模拟器中testingIn App Purchases,你需要一个iOS设备。
编辑:据我可以看到,当你尝试在模拟器上testingIAP会发生什么,购买代表不会被调用。
我想出了一些东西:
我在AppDelegate的-didFinishLaunching结束时立即启动了SKProductRequest,并且它从来没有工作过。
然后我打了个电话,等了3秒钟。 从此它开始工作。 因此,在启动应用程序后,您无法立即创buildStoreKit请求。
你的skProductRequest对象是在哪里声明的? 你可以用这个对象的全局声明来尝试它。