phonegap app用cordova-plugin-purchase说“商店未定义”

时间:2017-01-02 19:00:12

标签: cordova undefined cordova-plugins android-inapp-purchase

我在第一个phonegap应用中添加了https://github.com/j3k0/cordova-plugin-purchase,并尝试了此示例应用中的代码:https://github.com/Fovea/cordova-plugin-purchase-demo 我尝试了不同的方法,但在调试我的应用程序时总是告诉我“存储未定义”或进入“if(!windows.store)”。为什么呢?

// Our application's global object
var app = {};

app.nonHostedContentUrl = "http://ge.tt/api/1/files/3JSfJhL2/0/blob?download";

//
// Constructor
// -----------
//

app.initialize = function() {
    //log('initialize');

    // Listen to the deviceready event.
    // Make sure the score of 'this' isn't lost.
    document.addEventListener('deviceready', this.bind(this.onDeviceReady), false);
};

//
// Methods
// -------
//

// deviceready event handler.
//
// will just initialize the Purchase plugin
app.onDeviceReady = function() {
    //log('onDeviceReady');
    this.initStore();
};

// initialize the purchase plugin if available
app.initStore = function() {

    if (!window.store) {
        alert('Store not available');
        return;
    }

    app.platform = device.platform.toLowerCase();
    //document.getElementsByTagName('body')[0].className = app.platform;

    // Enable maximum logging level
    store.verbosity = store.DEBUG;

    // Enable remote receipt validation
    store.validator = "https://api.fovea.cc:1982/check-purchase";

    // Inform the store of your products
    //log('registerProducts');
    store.register({
        id:    'consumable1', // id without package name!
        alias: 'extra life',
        type:   store.CONSUMABLE
    });
}


// make sure fn will be called with app as 'this'
app.bind = function(fn) {
    return function() {
        fn.call(app, arguments);
    };
};

app.initialize();

我的第一次尝试是:

	function initializeStore() {

		if (!window.store) {
			alert('Window.Store not available');
			return;
		}
		
		if (!store) {
			alert('Store not available');
			return;
		}
		
		// Let's set a pretty high verbosity level, so that we see a lot of stuff
		// in the console (reassuring us that something is happening).
		store.verbosity = store.INFO;

		// We register a dummy product. It's ok, it shouldn't
		// prevent the store "ready" event from firing.
		store.register({
			id:    "myapp.inappid1",
			alias: "100 points",
			type:  store.CONSUMABLE
		});

		store.ready(function() {
			alert("\\o/ STORE READY \\o/");
		});

		store.refresh();
	}
	

	document.addEventListener('deviceready', initializeStore, false);

我也试过删除插件并从github添加它,就像在这里说的那样:Initialization Android In App Billing using cordova plugin

一些建议?

1 个答案:

答案 0 :(得分:2)

如果其他人正在寻找答案:此插件在phonegap开发者应用程序中不起作用!但它在发布时有效。