I am building and iOS and Android app (two apps).
I am looking for a replacement for Urban Airship which I do not longer trust. Mainly
because I see no prices anywhere.
I want to use Parse Push as a stand alone product. Is this possible?
I do not want to use any of the other Parse functionality.
As explained in the Parse Push notification ( iOS like Android ) setup at https://parse.com/docs/push_guide#setup/iOS
Yes, you could. Of course you will need to include the parse sdk, since you'll need to register the devices through the Parse system. So:
Once you register the device for receiving push notification ( iOS example )
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Store the deviceToken in the current Installation and save it to Parse.
PFInstallation *deviceInstallation = [PFInstallation currentInstallation];
[deviceInstallation setDeviceTokenFromData:deviceToken];
// this will be used later for sending push notifcations to this device
[deviceInstallation setChannels:#[deviceToken]];
[deviceInstallation saveInBackground];
}
Sending Push notification through iOS
PFPush *pushObj = [[PFPush alloc] init];
NSString* destDeviceToken = #"<DESTIONATION DEVICE TOKEN>";
// Through channels, you can uniquely identify devices or group of them for multicast
// push notification (imagine that more than one installation on your
// Parse database keep the same channel name).
// In this case we have set the channel name for each installation with the
// only unique deviceToken
[pushObj setChannels:#[destDeviceToken]];
// Push structure message
[pushObj setData:#{#"My Message!!",#"alert"}];
// send push ( so, send to parse server that handle the push notification
// request and deliver it for you)
[pushObj sendPushInBackground];
Sending Push notification through Android
String destDeviceToken = "<DESTIONATION DEVICE TOKEN>";
JSONObject data = new JSONObject("{\"alert\": \"My Message!!\"}");
ParsePush *push = new ParsePush();
push.setChannel(destDeviceToken);
push.setData(data);
push.sendPushInBackground();
Sending Push notification through Javascript (Cloud Code)
(it requires implementation on the Cloud code of Parse)
var destDeviceToken = '<DESTIONATION DEVICE TOKEN>';
Parse.Push.send({
channels: [ destDeviceToken ],
data: {
alert: "My Message!!"
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
Sending Push notification through REST call
(it allow you to perform a sending push notification without working on Parse anymore, so from any other platform that support a REST call)
curl -X POST \
-H "X-Parse-Application-Id: <YOUR PARSE APP ID>" \
-H "X-Parse-REST-API-Key: <YOUR REST API KEY>" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"<DESTIONATION DEVICE TOKEN>"
],
"data": {
"alert": "My Message!!",
}
}' \
https://api.parse.com/1/push
In this way you don't need any additional implementation, like registering users or something like that.
Hope it helps!
Related
I'm trying the new request verification process for Slack API on AWS Lambda but I can't produce a valid signature from a request.
The example showed in https://api.slack.com/docs/verifying-requests-from-slack is for a slash command but I'm using for an event subscription, especially, a subscription to a bot event (app_mention). Does the new process support event subscriptions as well?
If so, am I missing something?
Mapping template for Integration request in API Gateway. I can't get a raw request as the slack documentation says but did my best like this:
{
"body" : $input.body,
"headers": {
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end
#end
}
}
My function for verification:
def is_valid_request(headers, body):
logger.info(f"DECODED_SECRET: {DECODED_SECRET}")
logger.info(f"DECRYPTED_SECRET: {DECRYPTED_SECRET}")
timestamp = headers.get(REQ_KEYS['timestamp'])
logger.info(f"timestamp: {timestamp}")
encoded_body = urlencode(body)
logger.info(f"encoded_body: {encoded_body}")
base_str = f"{SLACK_API_VER}:{timestamp}:{encoded_body}"
logger.info(f"base_str: {base_str}")
base_b = bytes(base_str, 'utf-8')
dgst_str = hmac.new(DECRYPTED_SECRET, base_b, digestmod=sha256).hexdigest()
sig_str = f"{SLACK_API_VER}={dgst_str}"
logger.info(f"signature: {sig_str}")
req_sig = headers.get(REQ_KEYS['sig'])
logger.info(f"req_sig: {req_sig}")
logger.info(f"comparing: {hmac.compare_digest(sig_str, req_sig)}")
return hmac.compare_digest(sig_str, req_sig)
Lambda Log in CloudWatch. I can't show the values for security reasons but it seems like each variable/constant has a reasonable value:
DECODED_SECRET: ...
DECRYPTED_SECRET: ...
timestamp: 1532011621
encoded_body: ...
base_str: v0:1532011621:token= ... &team_id= ... &api_app_id= ...
signature: v0=3 ...
req_sig: v0=1 ...
comparing: False
signature should match with req_sig but it doesn't. I guess there is something wrong with base_str = f"{SLACK_API_VER}:{timestamp}:{encoded_body}". I mean, the concatination or urlencoding of the request body, but I'm not sure. Thank you in advance!
Notifications from OneSiganl for iOS 10 is not working. things i have rechecked again that i am using..
Xcode 8.1,
Swift 3,
Added latest provisioning cert,
Under capabilities push notifications are on with entitlement,
My app delegate methods are
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID)
OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
OneSignal.promptLocation();
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID, handleNotificationReceived: {
(Notification) in
}, handleNotificationAction: { (action) in
}, settings:[kOSSettingsKeyAutoPrompt: true ,
kOSSettingsKeyInFocusDisplayOption:OSNotificationDisplayType.notification.rawValue]) }
And for registering the device with id.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
OneSignal.sendTag("myType", value: "myBroadCast")
OneSignal.idsAvailable { (userId, deviceToken) in
let userId = String(format: "%#", userId!)
DataManager.sharedInstance.deviceToken = userId;
print("player id",userId)
}
I have got the playerid i.e userId apparently. So my device is registered successfully.
The thing is that the api notifications are not receiving on my device. Other than OneSignal sample push messages (which are working fine),
My API payload for notification is
{"alert":{"notification":{"notification_type":1,"v_n":"Custom Place","u_n":"customer","c_id":907,"m_id":1207,"m_t":"1","f_a":0,"d_d":"07 Dec, 2016","t_t":"07:40 AM","is_group_chat":true},"body":"hxuf"},"badge":1,"sound":"NewMessage.mp3"}
Please help me in this regard. As this problem is only with iOS 10 devices.
If your making a POST REST API call to https://onesignal.com/api/v1/notifications your JSON format isn't correct. The JSON payload should be as follows for the OneSignal notification based on your contents from your JSON example in your question.
{
"app_id": "YOUR_ONESIGNAL_APP_ID",
"contents": {"en": "hxuf"},
"ios_badgeType": "SetTo",
"ios_badgeCount": 1,
"ios_sound":"NewMessage.mp3",
"data": {"notification_type":1,"v_n":"Custom Place","u_n":"customer","c_id":907,"m_id":1207,"m_t":"1","f_a":0,"d_d":"07 Dec, 2016","t_t":"07:40 AM","is_gr`oup_chat":true}
}
Note1: You must set a targeting parameter such as include_player_ids as a JOSN array to a list of OneSignal player / user ids. Or use another targeting parameter such as included_segments. See the full tarting options in the OneSignal documentation page at the bottom of this answer.
Note2: .mp3 files can't be used for notification sounds for iOS. You must convert it to a .wav or .caf format.
See OneSignal's full documentation on the create REST API call endpoint below.
https://documentation.onesignal.com/reference#create-notification
I'm doing whatever i can to send ios push notifications to a react-native app and for that app to display notifications.
I've been trying to figure this out for months.
I have a local Parse server running with the following config:
{
"appId": "org.reactjs.native.example.ReactZeroNotifications",
"masterKey": "masterkey",
"databaseURI": "mongodb://localhost/test",
"push": {
"ios": [
{
"pfx": "reactnotification-dev.p12",
"bundleId": "org.reactjs.native.example.ReactZeroNotifications",
"passphrase": "*",
"production": false
},
{
"pfx": "reactnotification-prod.p12",
"bundleId": "org.reactjs.native.example.ReactZeroNotifications",
"passphrase": "*",
"production": true
}
]
}
}
I then send a post request to http://localhost:1337/parse/push with the following headers:
X-Parse-Application-Id: org.reactjs.native.example.ReactZeroNotifications
X-Parse-Master-Key: masterkey
and the following raw JSON data:
{"where": {"deviceType": "ios"},"data":{"alert": "hello NOTIFICATIONS!!"}}
Meanwhile I have a react-native app running with pushnotification linked as a library and I receive the register event with a token.
However, my notification event never goes off and I never see a notification at the top of my iPhone as I'm trying to accomplish.
(Note: I just want to see a notification on a react-native app... no matter how this is accomplished, I feel as if I could figure out the rest if I can just get it to work once)
As per recommendation i turned on verbose on the parse server and received the following after posting:
verbose: sending push to 0 installations
verbose: sent push!
0 success, 0 failures
i have a big problem on my IOS app. I follow the guide provide by appcelerator documentation to setup my iOS push notification. All seemed work fine, on my appcelerator dashboard i see under the device section my device registered with its token, and when i send a push notification on the detail's push (in push notification log) i read my id device number with a perfect Success(1).
But on my device i didn't receive any notification. I tried with my app opened and with my app closed, but nothing has showed. I don't know why this happen. On my android all work fine. Here my code:
//PUSH NOTIFICATION
var Cloud = require("ti.cloud");
//controllo se ho un token
var deviceToken = Ti.App.Properties.getString("deviceToken");
if ( deviceToken == "" || deviceToken == null) {
requireToken();
} else {
if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
subscribeToChannel(deviceToken);
}
}
//chiedo un token
function requireToken() {
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.API.warn( "entrato nella versione" )
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
Ti.Network.registerForPushNotifications({
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
});
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
}
// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
}
function deviceTokenSuccess(e) {
Ti.API.warn( "token ricevuto" )
Ti.App.Properties.setString("deviceToken", e.deviceToken);
subscribeToChannel(e.deviceToken);
}
function deviceTokenError(e) {
//error action
}
}
//controllo se sono iscritto alle notifiche push
if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
subscribeToChannel(deviceToken);
}
function subscribeToChannel (_deviceToken) {
Ti.API.warn( "subscribe fatta" )
Cloud.PushNotifications.subscribeToken({
device_token: _deviceToken,
channel: "ios_alerts",
type: Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function (e) {
if (e.success) {
Ti.App.Properties.setString("subscribed", "true");
}
});
};
function receivePush(e) {
Ti.API.warn("alert ricevuto" + JSON.stringify(e) )
alert(e)
}
is probably something related to your certificates on Apple panel.
Check if you enabled APS with your appid and if not, activate it, then generate another provisioning profiles and re-build the app.
You will also have to put a .p12 file in the Appcelerator platform website.
Just in case this is your issue(s):
Device Token Cannot be fetched if on Device in Debug mode, must be in Run Mode!
Remember that under ad-hock releases push notifications MUST use the sandbox 'gateway.sandbox.push.apple.com'
Chris
Ref: https://archive.appcelerator.com/question/148135/no-reply-from-tinetworkregisterforpushnotifications
I´m trying to get the pushwoosh plugin to work in a phonegap build app and all I get is an alert error that the aps environment is not found.
This is the steps I took.
Created a new appID that I enabled push notification on.
Created a new APNs Development Certificate. And downloaded it.
Created a new mobile provisioning profile and downloaded it and installed it on my phone.
Checked the mobile provisioning profile that it had "aps-environment" and "developer" in it.
In key chain I rightclicked the aps certificate and exported a .cer and a .p12 file and uploaded them to my newly created application on pushwoosh.com
I wrote the pushwoosh application id in my index file and the right id in the config file(same as in my mobile provisioning file)
I rightclicked my iPhone Developer Certificate in key chain and exported a .p12 file for phonegap and called it mypushapp.p12.
I created a new key at phonegap build and uploaded the mypushapp.p12 and the mobile provising file and then I build my app.
The app itself works as it should, but I get this aps error that it failed to register?
In my index file I init pushwoosh in the deviceready function and this is the pushwooshcode that I have.
function initPushwoosh() {
alert("init pushwoosh");
var pushNotification = window.plugins.pushNotification;
pushNotification.onDeviceReady();
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid:"5FB5C-E3F1F", appname:"newpushtest"},
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});
pushNotification.setApplicationIconBadgeNumber(0);
pushNotification.getTags(function(tags) {
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error) {
console.warn('get tags error: ' + JSON.stringify(error));
});
//start geo tracking. PWTrackSignificantLocationChanges - Uses GPS in foreground, Cell Triangulation in background.
pushNotification.startLocationTracking('PWTrackSignificantLocationChanges',
function() {
console.warn('Location Tracking Started');
});
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
navigator.notification.alert(notification.aps.alert);
//to view full push payload
//navigator.notification.alert(JSON.stringify(notification));
pushNotification.setApplicationIconBadgeNumber(0);
});
}
I don´t know where I go wrong so any input appreciated thanks.