方法未达到完成块 [英] Method does not reach Completion Block
本文介绍了方法未达到完成块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 SKStoreProductViewController
使用以下方法显示iTunes产品。该方法被调用,但我没有成功或错误。知道为什么吗?:
I'm using the SKStoreProductViewController
to display an iTunes product with the following method. The method gets called, but I get no success or error. Any idea why?:
@IBAction func BuySomething(sender : AnyObject) {
NSLog("%@","called");//gets called
let storeViewController:SKStoreProductViewController = SKStoreProductViewController();
storeViewController.delegate = self;
var someitunesid:String = "676059878";
var productparameters = [SKStoreProductParameterITunesItemIdentifier:someitunesid];
storeViewController.loadProductWithParameters(productparameters, { (success: Bool!, error: NSError!) -> Void in
if success {
NSLog("%@",success)//no call
self.presentViewController(storeViewController, animated: true, completion: nil);
} else {
NSLog("%@", error)//no call
}
})
}
推荐答案
由于某些原因 SKStoreProductViewController
在模拟器上不起作用,你必须在实际设备上尝试。
For some reasons SKStoreProductViewController
doesn't work on simulator, you must try it on actual device instead.
我刚刚在实际设备上尝试了这个,并获得了成功调用回调后在实际设备上的样子截图:
I just tried that on actual device and got an screenshot of how it looks like on the actual device after callback was called with success:
这是代码我'曾经这样做过:
And here is the code I've used to do it:
import UIKit
import StoreKit
class ViewController: UIViewController,SKStoreProductViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func BuySomething(sender : AnyObject) {
NSLog("%@","called");//gets called
let storeViewController:SKStoreProductViewController = SKStoreProductViewController();
storeViewController.delegate = self;
var someitunesid:String = "676059878";
var productparameters = [SKStoreProductParameterITunesItemIdentifier:someitunesid];
storeViewController.loadProductWithParameters(productparameters, {
(success: Bool!,error: NSError!) -> Void in
if success {
NSLog("%@",success)
self.presentViewController(storeViewController, animated: true, completion: nil);
} else {
NSLog("%@", error)
}
})
}
// this is SKStoreProductViewControllerDelegate implementation
func productViewControllerDidFinish(viewController: SKStoreProductViewController!) {
}
}
这篇关于方法未达到完成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文