سؤال

I am using the following code in insert to perform push notifications. TodoItem Table contains imageurl and Channel Table has channl uris. The reference for this code is here-http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-get-started-push-vs2012/

The following is the code for insert script in TodoItem Table

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);
                        }
                    });
                });
            }
        });
    }

The error is Error in callback for table 'Channel'. ReferenceError: item is not defined at :122:32 [external code] at Object.registrationsTable.read.success (:120:31) [external code]

Can anyone please let me know how to resolve this?

هل كانت مفيدة؟

المحلول

The problem is in this block of code: success: function(registrations) { }.

I would remove the call to push.wns and log to console to try to debug. Check that 'item' exists. If you're using the online node editor it will show you if you have any unmatched brackets.

I'm assuming you have configured WNS for use in the Azure portal?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top