I am trying to implement push to my app.
I've followed this guide:
http://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-ios-get-started-push/
However, I am using API's instead of the Data-scripts, so in one of my API methods I am doing this:
var push = request.service.push;
push.apns.send(null, {
alert: "Alert",
payload: {
inAppMessage: "Hey, a new item arrived"
}
}, {
success: function(resp) {
console.log(resp)
},
error: function(err) {
console.error(err)
}
});
My log is showing this (So I land in the success-method [Also I know that I should never land in error for iOS due to apples push server not responding with error]):
{ isSuccessful: true,
statusCode: 201,
body: '',
headers:
{ 'transfer-encoding': 'chunked',
'content-type': 'application/xml; charset=utf-8',
server: 'Microsoft-HTTPAPI/2.0',
date: 'Mon, 20 Oct 2014 11:31:21 GMT' },
md5: undefined }
My app is registered correctly like this, I see the callback message and no error:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken: (NSData *)deviceToken
{
[client.push registerNativeWithDeviceToken:deviceToken tags:#[#"uniqueTag"] completion:^(NSError *error)
{
NSLog(#"registerNativeWithDeviceToken callback");
if (error != nil)
{
NSLog(#"Error registering for notifications: %#", error);
}
}];
}
But no push message land in my iphone! Nothing is happening.
Im trying to check for errors in my Notification Hub but I see no log there.
What am I missing? I really don't get it where my actual device id is stored server side anyway. I must be missing something.
Thank you!
The best way to debug what is occurring is to follow the Notification Hub debugging steps here: http://msdn.microsoft.com/en-us/library/azure/dn530751.aspx
I would begin by using Service Bus Explorer to double-check the registration has the device token and tags you expect. After verifying that, please test sending an alert directly via the Notification Hub portal. If you still have issues, please send me an email at toddreif#microsoft.com.
Use your debug menu in Azure as #Todd Reifsteck said, and please test the tag name both "myTag" and myTag while debugging.
Related
I'm using node-apn to send push notifications to my device. Whenever I try, I get the following:
{ sent: [],
failed:
[ { device: '****',
status: '400',
response: [Object] } ] }
I'm fairly certain my device token is correct. Is there any way to find out more info about why this error occurs. Is there info in the "response"—if so how do I get it? It would be helpful to get one of the error strings listed here (https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) like "BadCollapseId"
Here is my node.js code for reference.
var deviceToken = "***";
var notification = new apn.Notification();
notification.topic = '*****';
notification.alert = "HI DER";
notification.payload = {id: 3};
apnProvider.send(notification, deviceToken).then(function(result) {
console.log(result);
});
The app is built using ionic 2, but I don't think that would make a difference.
Thanks!
Basically all I needed was this line:
console.log(result.failed);
instead of
console.log(result);
This gave me the code "DeviceTokenNotForTopic" and I was able to go from there!
Since few days I'm trying to implement the iOS in-app purchase verification on the beforeSave of a purchase (on sandbox), but it always fail.
I tried the receipt with postman, and it works.
So, it's the Parse.Cloud.httpRequest the problem.
I tried also to put the receipt directly in the Cloud Code and it's always the same error (21002). https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
Here is my code :
Parse.Cloud.httpRequest({
method: 'POST',
url:'https://sandbox.itunes.apple.com/verifyReceipt',
body:{'receipt-data':receipt},
success: function (httpResponse) {
console.log(httpResponse.text);
if (httpResponse.status == 0) {
// success
} else {
// error
}
},
error: function (httpResponse) {
// error
}
});
Is there someone that did it?
If this a auto-renewal subscription?
If so, you missed the password field:
password Only used for receipts that contain auto-renewable
subscriptions. Your app’s shared secret (a hexadecimal string).
in the jsonBody:
var jsonBody = {
"receipt-data" : reference,
"password" : "xxxxx"
};
Also you should JSON encode the POST BODY (node example in the following)
itunes_client.post("", {}, JSON.stringify(jsonBody),
I wrote a simple job to try sending a push notification to myself. Here's the code:
Parse.Cloud.job("testPush", function(request, status) {
Parse.Cloud.useMasterKey();
var installationQuery = new Parse.Query(Parse.Installation);
installationQuery.equalTo("user", "6t1JIuNqe1"); // I triple checked - this is the value of my user in the installation table.
Parse.Push.send({
where: installationQuery,
data: {
alert: "Test"
},
}, {
success: function() {
console.log("The Push Test Worked!");
status.success("All done with the push test!");
}, error: function(error) {
console.error("Something bad happened " + error);
status.error("Something bad happened during the Parse test...");
}
});
});
Although it logs in Parse that the job was run successfully, I never see a notification appear on my iPhone. I checked in Settings - it's all set up properly there (notifications are allowed to appear and should appear as banners, they should show up in notification center, they should show up on my lock screen). And yet the notification never appears.
What more do I need to check? What am I missing?
Pointer field should work with an instance.
Try replacing installationQuery.equalTo("user", "6t1JIuNqe1"); with the following:
var user = new Parse.User();
user.id = '6t1JIuNqe1';
installationQuery.equalTo('user', user);
I'm writing an app that uses push notifications widely, so push notifications reliability is very important for app.
I send push notification through parse cloud code function
Parse.Cloud.define("sendPush", function(request, response) {
var query = new Parse.Query(Parse.Installation);
query.equalTo('userObjectId', request.params.toUser);
query.exists("deviceToken");
Parse.Push.send({
where: query,
data: {
"alert": request.params.alert,
"sound": "default",
"type": request.params.type,
"status": request.params.status,
"fromUserId": request.params.fromUserId,
"fromUserName": request.params.fromUserName,
"messageId": request.params.messageId
}
}, { success: function() {
response.success("success");
}, error: function(err) {
response.error("error");
}
});
});
This function delivers pushes great if my iPhone is online. But if i turn off internet on my iPhone for 30 seconds and send push, this push is not delivered when i turn internet on. So i tried to set expiration date in my parse cloud code function to improve reliability of delivering pushes when device isn't online.
// Expiration_interval added
Parse.Cloud.define("sendPush", function(request, response) {
var query = new Parse.Query(Parse.Installation);
query.equalTo('userObjectId', request.params.toUser);
query.exists("deviceToken");
Parse.Push.send({
expiration_interval: 24 * 60 * 60,
where: query,
data: {
"alert": request.params.alert,
"sound": "default",
"type": request.params.type,
"status": request.params.status,
"fromUserId": request.params.fromUserId,
"fromUserName": request.params.fromUserName,
"messageId": request.params.messageId
}
}, { success: function() {
response.success("success");
}, error: function(err) {
response.error("error");
}
});
});
But it is still not working even if i turn off internet for just a 30 secs.
Thanks for any helps/ideas.
This is an artifact related to the Apple Quality of Service guidelines for the PUSH system.
In practice, it means that sometimes pushes will be missed. If they are crucial to your design, I suggest creating a database table of pushes that will deliver messages or data and have the app check on each load for new messages.
In practice, this means the push will not always get the attention of your users, but at least all the data will be delivered.
You can learn more at the parse.com help thread here: https://www.parse.com/questions/sending-push-notifications-quickly-causes-some-notifications-to-be-missed
As well as the Apple documentation here: http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW4
According to the docs at PushWhoosh:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
I should be able to use Adobe's Build cloud service to build PhoneGap apps. I've followed the instructions in the docs, but can't get my app to register with the PushWhoosh service (i.e.: it's not sending a device token).
I think the issue has to do with the registration of the plugin in config.xml. According to the Adobe Build docs, the only push plugin supported is their "GenericPush", which I've added to my config.xml file like so:
I've also whitelisted the pushwhoosh.com domain.
In my index.html file, I have the function initPushwhoosh, which gets called when the device is ready:
function initPushwoosh() {
try {
var pushNotification;
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
}
else {
pushNotification.register(tokenHandler, errorHandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN" });
}
}
catch (err) {
alert(err.message + "\n\n" + err.name);
}
}
And my tokenHandler function (I'm building for iOS) looks like:
function tokenHandler(result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
PushWoosh.appCode = "E0313-D27FA";
PushWoosh.register(result, function (data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function (errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
Through debugging, it looks like the "pushNotification.register" function never gets called, and the try/catch statement doesn't display any error messages. That function is:
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
PushNotification.prototype.register = function (successCallback, errorCallback, options) {
alert("about to register");
if (errorCallback == null) { errorCallback = function () { } }
if (typeof errorCallback != "function") {
alert("PushNotification.register failure: failure parameter not a function");
return;
}
if (typeof successCallback != "function") {
alert("PushNotification.register failure: success callback parameter must be a function");
return;
}
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
};
My thinking is that it has to do with the plugin declaration (<gap:plugin name="GenericPush" />) in config.xml; I've tried changing it to (based on some other sample code I found):
<gap:plugin name="PushPlugin"/>
But that didn't work either. Note: when I did this, I tried changing:
cordova.exec(successCallback, errorCallback, "GenericPush", "register", [options]);
to
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
The complete code can be found here:
https://github.com/appburnr/PushWhooshTest
I've tripled-checked the my PushWhoosh AppID is correct, but I can never get the app to appear as registered device in my PushWhoosh control panel.
Any ideas?
Are you sure this code is correct?
pushNotification.register(successHandler, errorHandler, { "senderID": "replace_with_sender_id", "ecb": "onNotificationGCM" });
Shouldn't it be the Project ID from GCM? It might explain why the device doesn't register for push notifications.
I'm not familiar with PushWoosh, but they do have a guide to how to achieve this with Build here:
http://www.pushwoosh.com/programming-push-notification/phonegap-build-push-plugin-integration/
Have you followed each step?
If you still haven't had success (I hope you have) try this guide:
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
I've built a solution using push notifications myself now, and found my biggest issue was that I hadn't set up the certificates. This guide is perfect.
ALSO remember that push notifications won't work in the emulator, only on a real device.