J'ai un étrange ici j'essaye d'employer PhoneGap-InAppPurchase-iOS pour ajouter l'achat d'application dans mon application de phonegap. Cependant, en charge sur l'iphone, l'appareil dit toujours 'TypeError: 'undefined' is not an object (evaluating 'cordova.exec')
et je pense qu'il arrête mon démarrage.Phonegap Construire dans iphone erreur d'exécution
Lorsque j'essaie de faire un achat, j'obtiens l'erreur ' InAppPurchase[js]: purchase error: product needs to be loaded before purchase, call storekit.load(...) first!'
mais voici mon index.js - vous pouvez voir à partir de là que je lance le storekit.load en premier. Je ne sais pas si les deux problèmes sont liés et cela empêche le reste du JS de fonctionner? D'après ce que je peux voir, je ne cours pas cordova.exec?
var app = {
initialize: function() {
this.bindEvents();
console.log("Attempting to init");
document.addEventListener('deviceready', this.onDeviceReady, false);
try {
FB.init({appId: "sdfsdfsdfsdfsd", nativeInterface: CDV.FB, useCachedDialogs: false});
console.log("FB Ready");
} catch (e) {
alert(e);
}
inappbilling.init(bSuccess, bError, {showLog:true}, "asdass");
},
bindEvents: function() {
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
window.storekit.init({
debug: true, /* Because we like to see logs on the console */
purchase: function (transactionId, productId) {
console.log('purchased: ' + productId);
},
restore: function (transactionId, productId) {
console.log('restored: ' + productId);
},
restoreCompleted: function() {
console.log('all restore complete');
},
restoreFailed: function (errCode) {
console.log('restore failed: ' + errCode);
},
error: function (errno, errtext) {
console.log('Failed: ' + errtext);
},
ready: function() {
var productIds = [
"com.asdad.asdads.asdasd"
];
window.storekit.load(productIds, function(validProducts, invalidProductIds) {
$.each(validProducts, function (i, val) {
console.log("id: " + val.id + " title: " + val.title + " val: " + val.description + " price: " + val.price);
});
if(invalidProductIds.length) {
console.log("Invalid Product IDs: " + JSON.stringify(invalidProductIds));
}
});
}
});
},
tokenHandler:function(msg) {
localStorage.setItem("Device", "ios");
console.log("Token Handler " + msg);
localStorage.setItem("PushID", msg)
},
errorHandler:function(error) {
console.log("Error Handler " + error);
alert(error);
},
// result contains any message sent from the plugin call
successHandler: function(result) {
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(this.successHandler, this.errorHandler,{"senderID":"asdasdadsasd","ecb":"app.onNotificationGCM"});
}
else {
pushNotification.register(this.tokenHandler,this.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
}
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
// iOS
onNotificationAPN: function(event) {
var pushNotification = window.plugins.pushNotification;
console.log("Received a notification! " + event.alert);
console.log("event sound " + event.sound);
console.log("event badge " + event.badge);
console.log("event " + event);
if (event.alert) {
navigator.notification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
},
// Android
onNotificationGCM: function(e) {
switch(e.event)
{
case 'registered':
if (e.regid.length > 0)
{
console.log("Regid " + e.regid);
localStorage.setItem("PushID", e.regid)
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model
// of the intermediary push server which must also be reflected in GCMIntentService.java
alert(e.message);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
};
function bSuccess(result) {
alert("woo - initialised");
}
function bError(error) {
alert(error);
}
function updateID() {
console.log("Updating ID on server");
var Username = localStorage.getItem("Username");
var SessionKey = localStorage.getItem("SessionID");
var PushID = localStorage.getItem("PushID");
alert(PushID);
$.mobile.loading('show', { theme: "b", text: "Loading", textonly: false});
$.ajax({
crossDomain: true,
contentType: "application/json; charset=utf-8",
url: "http://taasdasdasdasdgi.asdasdasdasdasd.com/Register.asmx/RegisterDevice",
data: { Username: Username, SessionKey: SessionKey, PushId:PushID, UUid:"moo", ProductType: localStorage.getItem("Device") },
dataType: "jsonp",
success: onDataReceived
});
function onDataReceived(data)
{
$.mobile.loading('hide', { theme: "b", text: "", textonly: false});
}
}
function successHandler1 (result) {
console.log(result);
var strResult = "";
if(typeof result === 'object') {
strResult = JSON.stringify(result);
} else {
strResult = result;
}
}
function errorHandler1 (error) {
console.log(error);
alert("ERROR: \r\n"+error);
}
function subscribe(){
// make the purchase
if (device.platform == 'android' || device.platform == 'Android') {
inappbilling.buy(successHandler1, errorHandler1,"asdasdsa");
}
else {
window.storekit.purchase("com.asdsaddas.asdasd.asdasdasd", 1);
}
console.log("Trying to buy");