方法未达到完成块

时间:2014-07-12 04:13:46

标签: ios in-app-purchase swift storekit

我使用SKStoreProductViewController使用以下方法显示iTunes产品。该方法被调用,但我没有成功或错误。知道为什么吗?:

@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
        }
    })
}

2 个答案:

答案 0 :(得分:14)

由于某些原因SKStoreProductViewController无法在模拟器上运行,您必须在实际设备上尝试使用它。

我刚刚在实际设备上尝试了这个,并获得了成功调用回调后在实际设备上的样子截图:

以下是我用过的代码:

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!) {

    }


}

enter image description here

答案 1 :(得分:0)

可能是我来得太晚了,但只有当您打开的应用不支持您所在的国家/地区时才会发生这种情况。

相反,它总是有效。

快乐编码!!!!!!