2017-02-23 16 views
0

如何從我的API函數獲取回調,以便將其轉發給我的API? 當我使用callback()時,我只是JavaScript的新手。它是 顯示callback()不是一個函數。我的APN功能可以從我的Node.js應用程序發送通知,但回調沒有顯示參考

function sendiosNotification(notification,callback){ 

    if(!notification.data.to){ 
     return callback({error : false, message : "receiver's deviceid is not available. could not send notificaion"}); 
    } 
    var client = new apns.Provider({ 
     cert:"./cert/cert.pem", 
     key:"./cert/key.pem", 
     production: true, 

    }); 
    var notifi = new apns.Notification(); 
    notifi.topic = "---" 
    notifi.alert = notification.data.message; 
    notifi.title = notification.data.username; 
    device_token = notification.data.to;  
    client.send(notifi,device_token).then(result =>{ 
     console.log(result); 
     callback() 
    }); 
} 

data來自我的API。我可以成功向我的設備發送通知,但該功能沒有發送任何迴應。

在我的API中使用sendios函數。

sendiosNotification({ data : data }) 

如何使用響應或回調將通知響應發送回API?

+0

你是如何在回調傳遞給sendiosNotification功能? – 2K01B5

+0

Passon回調。這只是代碼我有,如果你可以幫我 –

回答

1

這應該與工作

sendiosNotification({ data : data }, function(){ 
     console.log('callback called'); 
}); 
+0

雖然這段代碼可以解決這個問題,[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers )真的有助於提高你的帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – jmattheis

0

功能如何回調的工作

function i(num,cb){console.log(num), cb()}; 

i(1,function(){console.log("finish")}) 

輸出:

1 
finish 
相關問題