afterSave之后实现了推送消息到客户端,在自己的本地Ubuntu服务器测试时,是成功的,能够推送.并且接收到,服务器没错误日志.可是在部署到开发环境时,测试时,出现了以下错误.
at Promise..extend.resolve (/mnt/avos/cloud-code/nodemodules/avoscloud-sdk/lib/promise.js:308:7)
ERROR 2015-09-23 12:44:25 request uncaughtException url=/1/functions/StatusCommentItem/afterSave, msg=TypeError: Cannot call method 'success' of undefined

ERROR 2015-09-23 12:44:25 at Function..each..forEach (/mnt/avos/cloud-code/node_modules/avoscloud-sdk/node_modules/underscore/underscore.js:153:9)
ERROR 2015-09-23 12:44:25 at cloud_sandbox:[development] cloud/status_comment_item.js:25:9
ERROR 2015-09-23 12:44:25 at wrappedResolvedCallback (/mnt/avos/cloud-code/node_modules/avoscloud-sdk/lib/promise.js:389:38)
ERROR 2015-09-23 12:44:25 at wrappedResolvedCallback (/mnt/avos/cloud-code/node_modules/avoscloud-sdk/lib/promise.js:389:38)
ERROR 2015-09-23 12:44:25 at /mnt/avos/cloud-code/node_modules/avoscloud-sdk/lib/promise.js:394:27
ERROR 2015-09-23 12:44:25 at /mnt/avos/cloud-code/node_modules/avoscloud-sdk/lib/promise.js:309:24
ERROR 2015-09-23 12:44:25 at Function..each..forEach (/mnt/avos/cloud-code/node_modules/avoscloud-sdk/node_modules/underscore/underscore.js:153:9)
ERROR 2015-09-23 12:44:25 at Promise..extend.resolve (/mnt/avos/cloud-code/nodemodules/avoscloud-sdk/lib/promise.js:308:7)
ERROR 2015-09-23 12:44:25 at /mnt/avos/cloud-code/node_modules/avoscloud-sdk/lib/promise.js:309:24

看下这个文件第 25 行,调用 success 的对象是不是出了什么意外而变成 undefined 了。

还有,顺便提醒下,after 的 hook 是没有 response 参数的。因为该操作的已经操作了,存储服务只是「通知」你一下,所以 response 是没有意义的。

这段代码里面压根没有success这个对象,还有个奇怪的问题就是我在本地服务器测试是成功的,而不熟上去就不行了

是指:你对一个 undefined 调用了 success 方法,不是说有 success 这个对象。
能不能提供下 status_comment_item.js 这个文件的第 25 行代码?

require('cloud/visit.js').pushNotify(username,'msgcomment','有人回复了你的沙发旅');

var pushNotify = function(username, tag, message){
var queryId = new AV.Query("_User");
queryId.equalTo('username', username);
queryId.first().then(function (user) {
var insId = user ? user.get('installationId') : undefined;
if(insId && insId.length > 0){
console.log('push: username=' + username + ',installationId=' + user.get('installationId'));
require('cloud/push.js').send(insId, {
data: {
tag: tag,
username: username,
alert: message,
}
});
}
},function(err){
console.log("push notify err :" + err);
})
}

require('cloud/visit.js').pushNotify(username,'msgcomment','有人回复了你的沙发旅');(这是第25行代码)

解决了 是response.success引起的 按你说的 去掉response参数就行了

smile