I'm wondering if it's possible to get push notification through JS SDK?
With the JS SDK alone, it's not possible to receive push notifications. However, you should look into LiveQueries: http://blog.parse.com/announcements/parse-server-goes-realtime-with-live-queries/
They allow you to do many of the things you might want to do with push notifications, since traditional push notifications make less sense in a web app.
If you're using the JS SDK for React Native apps, you can also do push notifications through the APIs React Native provides (I should know, I wrote some of them!). They hook into the underlying iOS push notification system, and allow you to manage pushes from JS.
@andrewimm I found a react-native plugin can receive push notification in iOS and Android. But the issue is it doesn't use the parse sdk so that the installation object will not be updated in parse database.
The issue for live queries is that the app won't be able to get notified if the app is not in foreground. Am I right? Thanks.
Thanks for clarifying that you're using the SDK with React Native.
What you want to do is get the device token from React Native by registering for notifications. Once you have it, create a new Installation object with the installationId field set to your current installationId, and the deviceToken field set to your token from the push registration.
var installationController = Parse.CoreManager.getInstallationController();
installationController.currentInstallationId().then(function(iid) {
var installation = new Parse.Installation({
installationId: iid,
deviceToken: YOUR_TOKEN_HERE,
// add any other info, like channels, here
});
return installation.save();
}).then(function(installation) {
// from this point onwards, you can use Parse Push to target your device
});
I'm actually actively in the process of adding new APIs to simplify this process for React Native apps, which I'd like to release in version 1.10
Parse is widely used in Ionic Apps too, not only react native and websites.
So, it would be great if JS-SDK support Push and Installation config out of the box.
@cleever the bigger issue is that a JavaScript library can't support Push, any more than Objective-C or Java can support Push. It's an OS-level activity, and we need to rely on the platform APIs providing access to the necessary info.
Currently, the JS SDK only generates an installationId for Sessions -- it doesn't generate true Installation class objects the way the Android or iOS SDKs do. However, Parse.Installation is still a class that wraps the custom _Installation class, and allows you to construct them as I described above. I shouldn't have explicitly said I'm working on an RN API -- I'm working on a generic API that will make it easy to take a token and save an installation object to the DB. As long as you can get ahold of the token for your platform, we'll make it easy to save an installation. The issue is that this requires some significant changes under the hood if we want to support caching Installation objects across sessions (which I do), and simultaneously maintain backwards compatibility.
I'm also exploring the work necessary to add platforms like Windows and Tizen to the parse-server, so that they can be targeted for pushes as well.
Sure. Actually we have some community driven cordova plugins that help with this low level activities like:
Ex.:
https://github.com/taivo/parse-push-plugin
However, they are too decentralized with a lot of forks.
So, an official support would be welcome, mainly in terms of token/Parse.Installation.
It's good to hear that you are working in a generic API, it will be very helpful.
Thank you @andrewimm
@cleever As @andrewimm mentioned Push is os level activity and have to use ios, android sdk to support so that I think it's not possible to support it only by JS SDK. So cordova plugin or RN plugin have to be used.
But I agree a standard interface for device token/Parse.Installation will be a great help. Thank you all.
@andrewimm could you give a more complete example please? I'm using the module react-native-device-info at the moment and have get a Installation. BUT the pushes all stay on the status "sending" and never get send. Is the following approach OK?
var DeviceInfo = require('react-native-device-info');
var installationController = Parse.CoreManager.getInstallationController();
installationController.currentInstallationId().then(function(iid) {
var installation = new Parse.Object('_Installation')
installation.set('deviceToken',token)
installation.set('deviceType',DeviceInfo.getManufacturer() == 'Apple' ? "ios" : "android")
installation.set('installationId',iid)
installation.set('appName',"schneewittchen")
installation.set('channels',[])
installation.set('appIdentifier', DeviceInfo.getBundleId())
installation.set('appVersion',DeviceInfo.getVersion())
installation.set('pushType',DeviceInfo.getManufacturer() == 'Apple' ? "APN" : "GCM")
installation.set("deviceManufacturer", DeviceInfo.getManufacturer());
installation.set("deviceBrand", DeviceInfo.getBrand());
installation.set("deviceModel", DeviceInfo.getModel());
installation.set("deviceID", DeviceInfo.getDeviceId());
installation.set("systemName", DeviceInfo.getSystemName());
installation.set("systemVersion", DeviceInfo.getSystemVersion());
installation.set("bundleID", DeviceInfo.getBundleId());
installation.set("buildNumber", DeviceInfo.getBuildNumber());
installation.set("deviceName", DeviceInfo.getDeviceName());
installation.set("userAgent", DeviceInfo.getUserAgent());
installation.set("deviceLocale", DeviceInfo.getDeviceLocale());
installation.set("deviceCountry", DeviceInfo.getDeviceCountry());
installation.set('user',user)
installation.save().then(console.log,console.warn)
}).then(function(installation) {
console.warn("installation",installation)
}).catch(console.warn)
@andrewimm im using the parse/react-parse module in my react native app and attempting to save and installation object, however this line
_installationController.currentInstallationId().then(function(iid) {_
from your comment above, is returning an empty object and as a result im getting an undefined object error when i try to get the currentInstallationId(). Any ideas?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Thanks for clarifying that you're using the SDK with React Native.
What you want to do is get the device token from React Native by registering for notifications. Once you have it, create a new
Installationobject with theinstallationIdfield set to your current installationId, and thedeviceTokenfield set to your token from the push registration.I'm actually actively in the process of adding new APIs to simplify this process for React Native apps, which I'd like to release in version 1.10