PhoneGap - 由于页面加载而重置插件

时间:2013-10-07 11:30:28

标签: ios cordova phonegap-plugins

我在整合原生EmailComposer时遇到了phonegap的问题。

MailComposer应该按下按钮打开,但它没有显示IOS的mailComposer,android的相同代码正在工作,

我的代码如下:

        <html>
        <head>
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
            <script type="text/javascript" charset="utf-8" src="emailcomposer.js"></script>

            <script type="text/javascript">
            document.addEventListener("deviceready", deviceready, true);
            function deviceready() {
                console.log("Device ready");
            }.
            //function to send mail using mail composer
            function composeText(){
var vehiclemileage = document.getElementById('vehiclemileage').value;
var vehiclemodel = document.getElementById('vehiclemodel').value;
var message1 = document.getElementById('message_body').value;
var vechicleyear = document.getElementById("yeardropdown");
var strUser = vechicleyear.options[vechicleyear.selectedIndex].value;
var vehiclemake = document.getElementById("vehiclemake");
var makevehicle = vehiclemake.options[vehiclemake.selectedIndex].value;

var deviceName = device.platform;
var devicemodel = device.model;


if(vehiclemodel == '' || makevehicle == ''){
alert("Please Enter all the Value");

 navigator.notification.alert(
        'Please Enter all the Value', // message
        alertDismissed,              // callback
        'Vehicle and Model',        // title
        'Ok'                       // buttonName
    );
 }
else
{
            //function to check folder named "RepairMyCar" and extract picture from folder to attach it to mail
                var attachPath; 
                var attachFile= new Array();
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
                    fileSystem.root.getDirectory("RepairMyCar", {
                        create: true
                    }, 
        function(directory) {
            console.log("Final 63" + directory.fullPath);
            attachPaths = directory.fullPath;
            var attachPath=attachPaths.slice(7,attachPaths.length);
            var directoryReader = directory.createReader();
            directoryReader.readEntries(function(entries) {
                var i;
                for (i=0; i<entries.length; i++) {
                    console.log(entries[i].name);
attachFile[i] =attachPath + "/" + entries[i].name;
                            }
                            console.log(attachFile);
                        }, 
                        function (error) {
                            alert(error.code);
                        });

                    });
                }, function(error) {
                    alert("can't even get the file system: " + error.code);
                });
                var dated, fnamed, phoned, emailed;
                 if(typeof(Storage)!=="undefined")
{
 dated = localStorage.date;
 fnamed = localStorage.fname;
 phoned = localStorage.phone;
 emailed= localStorage.email;
}

                console.log(attachFile);
                var newattachment = attachFile.toString();
                //Open mail composer with all datas
 setTimeout(function(){window.plugins.emailComposer.showEmailComposerWithCallback(null,
                    "Get an Estimate",
                     "Date: " + dated + '<br>' + "First Name: " + fnamed +  '<br>' + "Phone Number: " + phoned +  '<br>' + "Email Address: " + emailed +   '<br>' + "Year of Vehicle: " + strUser +  '<br>' + "Make of Vehicle: " + makevehicle +  '<br>' +  "Model of Vehicle: " + " " + vehiclemodel + '<br>' + 
                     "Mileage of Vehicle: " + " " + vehiclemileage + '<br>' +  message1 + '<br>' + "Sent from My:" + deviceName + devicemodel,
                [sth@sth.com],
                    [],
                    [],
                    true,
                    attachFile
                    );},100);
                //Clear LoccalStorage
                localStorage.clear();
            //exit the app after clicking this button
            navigator.app.exitApp();
            // navigator.camera.cleanup(onSuccess,fail);
            // function onSuccess(){
            // }
            // function fail(){
            // }
        }
}
        function onFail(message) {
            alert('Failed because: ' + message);
        }

    /***********************************************
    * Drop Down Date select script- by JavaScriptKit.com
    * This notice MUST stay intact for use
    * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
    ***********************************************/
    //function to  load year in drodown. Default selected year : Current Year
    function populatedropdown(yearfield){
        var today=new Date()
        var yearfield=document.getElementById(yearfield)
        for (var i=0; i<31; i++)
            //Select Year
    var thisyear=today.getFullYear()
    for (var y=0; y<25; y++){
        yearfield.options[y]=new Option(thisyear, thisyear)
        thisyear-=1
    }
    yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
    }
    </script>

    </head>
    <body>
        <div class="wrapper">
            <h1>Get a Repair Estimate</h1>
            <div class="main-content">
    <p>
                Please Enter the Year, Make, Model and Mileage of Your Vehicle and any other information we should know.
                </p>
                <form class="vehicle-detail-form">
                <ul>
                    <li>
                        <label>Year of Vehicle: </label>
                        <form action="" name="someform">
                        <select id="yeardropdown">
                        </select> 
                    </form>

                    <script type="text/javascript">

    //populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
    window.onload=function(){
        populatedropdown("yeardropdown")
    }
    </script>
                    </li>
                    <!-- Vehicle Year Selection -->

    <li><label>Model of Vehicle:</label>
    <input type="text" name="vehiclemodel" id = "vehiclemodel">
    </li>
    <li><label>Mileage of Vehicle:</label>
    <input type="number" name="vehiclemileage" id = "vehiclemileage"></li>
    <li>
        <textarea  name="message_body" id = 'message_body'  placeholder="Add Notes here(if any)"></textarea>
    </li>
    </form>
    <div style="clear:both;"></div>
    <div class="large-button-wrapper">
    <button onclick="composeText();">Get Your Estimate</button>
    </div>  
    </div>
    </div>
    </body>
    </html>

我已按照this link

中的说明将EmailComposer.h和EmailComposer.m保存在插件文件夹中

1 个答案:

答案 0 :(得分:1)

如果你在iOS项目上工作,我找到了一个解决方法。我有同样的问题。

在骨干路由器console.log中的视图更改停止在Xcode中工作后,您可以在Mac上使用Safari Web Inspector。每个console.log都可见。