2012-12-06 21 views
3

我一直在搜索這個問題的答案。我已經下載併成功安裝了PhoneGap的EmailComposer插件。我可以點擊我的「電子郵件」按鈕,電子郵件字段彈出沒有問題。問題是,我試圖預先填充「收件人:」字段和「主題」字段。我已經搜查各個崗位(主要是在計算器上),我已經看到了一些類似的帖子,但沒有與此完全一樣的問題,或者真正的解決辦法:PhoneGap:嘗試預先填寫使用電子郵件編輯器發送的電子郵件

帖子我已經試過: PhoneGap Email Composer Plugin How to send email using mail composer plugin in iphone using phone gap jQuery mobile

我能找到的最近的地方已經在這裏: https://groups.google.com/forum/#!searchin/phonegap/EmailComposer/phonegap/ItUj30UZnig/XTaBK7B8ahsJ

但是我還沒有找到解決方案。

如上所述。我所要做的就是預先填充「收件人:」和「主題:」字段。附帶的DOC EmailComposer.js看起來是這樣的:

// window.plugins.emailComposer 

function EmailComposer() { 
this.resultCallback = null; // Function 
} 

EmailComposer.ComposeResultType = { 
    Cancelled:0, 
    Saved:1, 
    Sent:2, 
    Failed:3, 
    NotSent:4 
} 


// showEmailComposer : all args optional 
EmailComposer.prototype.showEmailComposer = function(subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) { 

    var args = {}; 

    if(toRecipients) 
     args.toRecipients = toRecipients; 
    if(ccRecipients) 
     args.ccRecipients = ccRecipients; 
    if(bccRecipients) 
     args.bccRecipients = bccRecipients; 
    if(subject) 
     args.subject = subject; 
    if(body) 
     args.body = body; 
    if(bIsHTML) 
     args.bIsHTML = bIsHTML; 

    cordova.exec(null, null, "EmailComposer", "showEmailComposer", [args]); 

} 

// this will be forever known as the orch-func -jm 
EmailComposer.prototype.showEmailComposerWithCB =  function(cbFunction,subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) { 
    alert("email showEmailComposerWithCB?"); 
    this.resultCallback = cbFunction; 
    this.showEmailComposer.apply(this, [subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML]); 
} 

EmailComposer.prototype._didFinishWithResult = function(res) { 
    this.resultCallback(res); 
} 



cordova.addConstructor(
    function() { 
     if(!window.plugins) { 
      window.plugins = {}; 
     } 

     // shim to work in 1.5 and 1.6 
     if (!window.Cordova) { 
      window.Cordova = cordova; 
     }; 

     //window.plugins.emailComposer.showEmailComposer(subject,body,toRecipients,ccRecipients,bccRecipients,bIsHTML) 
     window.plugins.emailComposer = new  EmailComposer(); 
    } 
); 

啓動與實際行:

EmailComposer.prototype.showEmailComposer 

從未真正開槍。在面向公衆的一面,我有這樣的(它是有效的HTML,但我刪除了一些標籤張貼目的:

<a onclick="cordova.exec(null, null, 'EmailComposer', 'showEmailComposer', [args]);">Send Email</a> 

那麼我:

app.initialize(); 
var args; 

這恰好當第一次加載頁面

上,我做錯了什麼在這裏的任何想法?

回答

0

(由OP在一個問題的編輯。搬到一個社區維基答案回答。見Question with no answers, but issue solved in the comments (or extended in chat)

的OP寫道:

我想通了!解決方案相對比較簡單,但對於我來說,在頭幾個小時內我無法得到它。

在你的HTML代碼,無論你的按鈕,把這個:

<a onclick="sendEmail(); return false;">Send Email Now</a> 

sendEmail()功能是這裏的生意,所以在同一頁上,創建一個腳本標籤,並添加以下:

<script> 
    function sendEmail(){ 
     window.plugins.emailComposer.showEmailComposer("subject","body", "[email protected]", "[email protected]", "[email protected]",false); 
    } 
</script> 

在之後的同一HTML喲烏爾應用程序已被初始化,只需添加args變量:

app.initialize(); //under this 
var args = {}; 

保持EmailComposer.js文件相同的,都應該很好。爲了尋找這個答案,我跑了大量的帖子,人們可以通過主題行,但無法通過身體或其他任何東西。我測試了一下,這將正確地通過所有領域。我希望這可以幫助別人。

相關問題