2014-07-14 30 views
0

每次在我的iOS應用中創建新用戶時,我都希望發送一封電子郵件。我使用Parse.com作爲我的後端,並一直在閱讀Cloud Code。我假設我可以使用它來監視對象的創建,並啓動一個函數來在數據庫中創建特定對象(用戶)時發送電子郵件。我知道我可以在CloudCode中創建一個函數,然後在創建用戶時在我的iOS應用程序中調用此函數,但是我希望能夠在不向App Store提交更新的情況下做同樣的事情。有沒有辦法在不提交新的二進制文件的情況下完成此任務?使用Parse.com通過iOS應用創建新用戶時發送電子郵件

回答

5

您可以添加afterSave雲代碼功能,那麼您不需要更改您的應用程序 - 每次保存用戶對象時都會調用新代碼。此示例使用SendGrid,因此您需要一個SendGrid帳戶

Parse.Cloud.afterSave(Parse.User, function(request) { 

    if(!(request.object.existed())){ 
     var SendGrid = require("sendgrid"); 
     SendGrid.initialize("username", "password"); 

     SendGrid.sendEmail({ 
      to: "[email protected]", 
      from: "[email protected]", 
      subject: "Hello from Cloud Code!", 
      text: "Using Parse and SendGrid is great!" 
     }, { 
      success: function(httpResponse) { 
      console.log(httpResponse); 
      }, 
      error: function(httpResponse) { 
      console.error(httpResponse); 
      } 
     }); 
    } 
}); 
相關問題