I'm building an iOS app that connects to an Azure Mobile Service Backend to send push notifications - everytime a new item is inserted in a table. It seems that the registration is not working, because in the dashboard of the notification hub I can see some "Registration Operations", but I can't see any registrations in Visual Studio Server Explorer, also Push Notifications are not arriving on the device.
I use this code to register for remote notifications on my iOS client. This code runs fine, I don't get any errors.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[self.client.push registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError *error) {
if (error != nil) {
NSLog(@"Error registering for notifications: %@", error);
}
}];
}
This code is executed to insert a new item in the table storage of the mobile service.
NSDictionary *dbitem = @{ @"message" : @"test"};
MSTable *itemTable = [client tableWithName:@"TestTable"];
[itemTable insert:dbitem completion:^(NSDictionary *insertedItem, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"Item inserted, id: %@", [insertedItem objectForKey:@"id"]);
}
}];
Inserting works fine, the items show up in the table storage. Everytime a new item is inserted in the table, this script will run (Javascript - Node.js Backend)
function insert(item, user, request) {
var userId = user.userId;
request.execute({
success: function() {
request.respond();
push.apns.send(userId, {
alert: "Hello!",
payload: {
inAppMessage: item.message
}
});
}
});
}
And finally here is the registration script I'm using to register a new user for push notifications.
exports.register = function (registration, registrationContext, done) {
// Get the ID of the logged-in user.
var userId = registrationContext.user.userId;
console.log("userid: %j", userId);
// Perform a check here for any disallowed tags.
if (!validateTags(registration))
{
// Return a service error when the client tries
// to set a user ID tag, which is not allowed.
done("You cannot supply a tag that is a user ID");
console.log("failed registraion");
}
else{
// Add a new tag that is the user ID.
registration.tags.push(userId);
console.log("done registraion");
// Complete the callback as normal.
done();
}
};
function validateTags(registration){
for(var i = 0; i < registration.tags.length; i++) {
console.log(registration.tags[i]);
if (registration.tags[i]
.search(/facebook:|twitter:|google:|microsoft:/i) !== -1){
return false;
}
return true;
}
}
As you can see in the screenshot of the Visual Studio Server Explorer - there are no registrations for the notification hub.
The output of the monitor tab in the management portal is here.
I know that this is quite a long question, but if you know what the problem of not arriving push notifications could be - please let me know! Thank you