Ios应用程序内购买RequestData函数未触发?

时间:2014-05-09 15:29:37

标签: javascript ios cordova in-app-purchase

我正在使用phonegap 2.6.0 in,ios 7 sdk,设备是5.1。我已实施了应用内购买管理器plugin

在deviceready函数上,我试过调用requestData()函数,但它没有触发,因为它应该是

function onDeviceReady(){
    alert(window.plugins.inAppPurchaseManager); //-->This alerts as Object

    window.plugins.inAppPurchaseManager.onPurchased = function(transactionIdentifier, productId, transactionReceipt) {
        updatePurchaseTable(productId);
        window.location.reload();
        console.log('purchased: ' + productId);
    }

    window.plugins.inAppPurchaseManager.onRestored = function(transactionIdentifier, productId, transactionReceipt) {
        console.log('restored: ' + productId);
         /*See the developer guide for details of what to do with this */
    }

    window.plugins.inAppPurchaseManager.onFailed = function(errno, errtext) {
        alert('failed: ' + errtext);
    }
    window.plugins.inAppPurchaseManager.requestProductData("ProductId1", function(result) {
            alert(result.id);  //-->this doesn't happen
            console.log("productId: " + result.id + " title: " + result.title + " description: " + result.description + " price: " + result.price);
                  //window.plugins.inAppPurchaseManager.makePurchase(result.id, 1);
            }, function(id) {
            alert("Invalid product id: " + result.id);
            }
    );


}

我的config.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<widget>
    <preference name="AllowInlineMediaPlayback" value="false" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="BackupWebStorage" value="cloud" />
    <preference name="DisallowOverscroll" value="false" />
    <preference name="EnableLocation" value="false" /><!-- DEPRECATED -->
    <preference name="EnableViewportScale" value="false" />
    <preference name="FadeSplashScreen" value="true" />
    <preference name="FadeSplashScreenDuration" value=".25" />
    <preference name="HideKeyboardFormAccessoryBar" value="false" />
    <preference name="KeyboardDisplayRequiresUserAction" value="true" />
    <preference name="KeyboardShrinksView" value="false" />
    <preference name="MediaPlaybackRequiresUserAction" value="false" />
    <preference name="ShowSplashScreenSpinner" value="true" />
    <preference name="SuppressesIncrementalRendering" value="false" />
    <preference name="TopActivityIndicator" value="gray" />

    <content src="index.html" />

    <plugins>
        <plugin name="Device" value="CDVDevice" />
        <plugin name="Logger" value="CDVLogger" />
        <plugin name="Compass" value="CDVLocation" />
        <plugin name="Accelerometer" value="CDVAccelerometer" />
        <plugin name="Camera" value="CDVCamera" />
        <plugin name="NetworkStatus" value="CDVConnection" />
        <plugin name="Contacts" value="CDVContacts" />
        <plugin name="Debug Console" value="CDVDebugConsole" />
        <plugin name="Echo" value="CDVEcho" />
        <plugin name="File" value="CDVFile" />
        <plugin name="FileTransfer" value="CDVFileTransfer" />
        <plugin name="Geolocation" value="CDVLocation" />
        <plugin name="Notification" value="CDVNotification" />
        <plugin name="Media" value="CDVSound" />
        <plugin name="Capture" value="CDVCapture" />
        <plugin name="SplashScreen" value="CDVSplashScreen" />
        <plugin name="Battery" value="CDVBattery" />
        <plugin name="Globalization" value="CDVGlobalization" />
        <plugin name="InAppBrowser" value="CDVInAppBrowser" />

        <platform name="ios">
            <config-file target="config.xml" parent="/*">
                <feature name="InAppPurchaseManager">
                    <param name="ios-package" value="InAppPurchaseManager" />
                </feature>
            </config-file>

            <!-- Note: the ios src is based off src/ios implicitly -->
            <header-file src="InAppPurchaseManager.h" />
            <source-file src="InAppPurchaseManager.m" />
            <framework src="StoreKit.framework" />
        </platform>
    </plugins>
    <access origin="*" />
</widget>

并且.h和.m文件位于项目源中的plugins文件夹中。

我也在本地发出警告

  

InAppPurchaseManager.m

文件在- (void) requestProductData:(CDVInvokedUrlCommand*)command函数中也没有显示任何警报。

1 个答案:

答案 0 :(得分:0)

这里有一个更新近流行的iOS IAP插件:https://github.com/j3k0/PhoneGap-InAppPurchase-iOS

最终会更好。