Cordova/Phonegap 3.0.0 plugin for Parse.com push service
Using Parse.com's REST API for push requires the installation id, which isn't available in JS
This plugin exposes the four native Android API push services to JS:
cordova plugin add https://github.com/nickh364/phonegap-parse-plugin.git
phonegap local plugin add https://github.com/nickh364/phonegap-parse-plugin.git
import com.parse.ParseAnalytics;
ParseAnalytics.trackAppOpenedInBackground(getIntent());
<receiver android:name="com.example.PushReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.push" />
</intent-filter>
</receiver>
if(key.equals("id")){
ParsePlugin.key = json.getString(id);
}
Intent i = new Intent(context, YOUR_CORDOVA_ACTIVITY.class);
Usage iOS -----
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else
#endif
{
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
[Parse setApplicationId:@"Your Application ID"
clientKey:@"Your Client Key"];
if (application.applicationState != UIApplicationStateBackground) {
// Track an app open here if we launch with a push, unless
// "content_available" was used to trigger a background push (introduced
// in iOS 7). In that case, we skip tracking here to avoid double
// counting the app-open.
BOOL preBackgroundPush = ![application respondsToSelector:@selector(backgroundRefreshStatus)];
BOOL oldPushHandlerOnly = ![self respondsToSelector:@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)];
BOOL noPushPayload = ![launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateInactive) {
// The application was just brought from the background to the foreground,
// so we consider the app as having been "opened by a push notification."
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}
#import "CDVParsePlugin.h"
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
CDVParsePlugin *parsePlugin = [[CDVParsePlugin alloc] init];
[parsePlugin handleBackgroundNotification:notificationPayload];
Add this to your AppDelegates didReceiveRemoteNotification if (application.applicationState == UIApplicationStateInactive) {
NSDictionary *notificationPayload = userInfo;
CDVParsePlugin *parsePlugin = [[CDVParsePlugin alloc] init];
[parsePlugin handleBackgroundNotification:notificationPayload];
- (void)handleBackgroundNotification:(NSDictionary *)notification
{
if ([notification objectForKey:@"id"])
{
storyURL = [notification objectForKey:@"id"];
}
}
{
"aps": {
"badge": 1,
"alert": "Hello world!",
"sound": "cat.caf"
},
"id": 4567
}
#### iOS Frameworks used
- AudioToolbox.framework
- CFNetwork.framework
- CoreGraphics.framework
- CoreLocation.framework
- libz.1.1.3.dylib
- MobileCoreServices.framework
- QuartzCore.framework
- Security.framework
- StoreKit.framework
- SystemConfiguration.framework
- src/ios/Frameworks/Parse.framework
<script type="text/javascript>
var parsePlugin = = window.parsePlugin;
parsePlugin.getInstallationId(function(id) {
alert(id);
}, function(e) {
alert('error');
});
parsePlugin.getSubscriptions(function(subscriptions) {
alert(subscriptions);
}, function(e) {
alert('error');
});
parsePlugin.subscribe('SampleChannel', function() {
alert('OK');
}, function(e) {
alert('error');
});
parsePlugin.unsubscribe('SampleChannel', function(msg) {
alert('OK');
}, function(e) {
alert('error');
});
// I am using this to get a id from the notification
parsePlugin.getNotification(function(id) {
alert(id);
}, function(e) {
alert('error');
});
</script>
Phonegap/cordova > 3.0.0