我在insert中使用以下代码来执行推送通知。 TodoItem表包含imageurl和Channel Table有channl uris。此代码的引用位于此处 - http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-get-started-push-vs2012/
以下是TodoItem表中插入脚本的代码
var azure = require('azure');
var qs = require('querystring');
var appSettings = require('mobileservice-config').appSettings;
function insert(item, user, request) {
// Get storage account settings from app settings.
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
var host = accountName + '.blob.core.windows.net';
if ((typeof item.containerName !== "undefined") && (
item.containerName !== null)) {
// Set the BLOB store container name on the item, which must be lowercase.
item.containerName = item.containerName.toLowerCase();
// If it does not already exist, create the container
// with public read access for blobs.
var blobService = azure.createBlobService(accountName, accountKey, host);
blobService.createContainerIfNotExists(item.containerName, {
publicAccessLevel: 'blob'
}, function(error) {
if (!error) {
// Provide write access to the container for the next 5 mins.
var sharedAccessPolicy = {
AccessPolicy: {
Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
}
};
// Generate the upload URL with SAS for the new image.
var sasQueryUrl =
blobService.generateSharedAccessSignature(item.containerName,
item.resourceName, sharedAccessPolicy);
// Set the query string.
item.sasQueryString = qs.stringify(sasQueryUrl.queryString);
// Set the full path on the new new item,
// which is used for data binding on the client.
item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
} else {
console.error(error);
}
request.execute({
success: function() {
request.respond();
sendNotifications();
}
});
});
} else {
request.execute({
success: function() {
request.respond();
sendNotifications();
}
});
}
}
function sendNotifications() {
var registrationsTable = tables.getTable('Channel');
registrationsTable.read({
success: function(registrations) {
registrations.forEach(function(registration) {
push.wns.sendToastText04(registration.handle, {
text1: item.text
}, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse);
}
});
});
}
});
}
表'Channel'的回调错误是错误。 ReferenceError:未定义item at:122:32 [外部代码] at Object.registrationsTable.read.success(:120:31) [外部代码]
任何人都可以告诉我如何解决这个问题吗?
答案 0 :(得分:0)
问题出在这段代码中:success:function(registrations){}。
我会删除对push.wns的调用并登录到控制台以尝试调试。检查'item'是否存在。如果您正在使用在线节点编辑器,它将显示您是否有任何不匹配的括号。
我假设您已配置WNS以在Azure门户中使用?