Method does not reach Completion Block

情到浓时终转凉″ 提交于 2019-12-05 15:44:14

问题


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

回答1:


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

    }


}



来源:https://stackoverflow.com/questions/24709586/method-does-not-reach-completion-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!