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/bostondv/phonegap-parse-plugin.git
phonegap local plugin add https://github.com/bostondv/phonegap-parse-plugin.git
You must create an Application class to ensure Parse.initialize() is always called before the service is started.
-
Create a file
MainApplication.javainplatforms/android/src/<your package name> -
Add following contents replacing
<MainActivityClass>with the class name of your main CordovaActvity,YOUR_APP_IDandYOUR_CLIENT_KEYwith appropriate Parse keys, and<com.example.app>with your package name.
package <com.example.app>
import android.app.Application;
import android.content.Context;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class MainApplication extends Application {
private static MainApplication instance = new MainApplication();
public MainApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "YOUR_APP_ID", "YOUR_CLIENT_KEY");
PushService.setDefaultPushCallback(this, <MainActivityClass>.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
- Update
AndroidManifest.xmlto reference the MainApplication class by addingandroid:name="you.package.name.MainApplication"to<application>. Replaceyour.package.namewith the name of your applications package.
<receiver android:name="com.example.PushReceiver" android:exported="false">
<intent-filter>
<action android:name="com.example.push" />
</intent-filter>
</receiver>
if(key.equals("url")){
ParsePlugin.key = json.getString(key);
}
Usage iOS -----
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
#import "CDVParsePlugin.h"
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
CDVParsePlugin *parsePlugin = [[CDVParsePlugin alloc] init];
[parsePlugin handleBackgroundNotification:notificationPayload];
- (void)handleBackgroundNotification:(NSDictionary *)notification
{
if ([notification objectForKey:@"url"])
{
// do something with job id
storyURL = [notification objectForKey:@"url"];
}
}
{
"aps": {
"badge": 1,
"alert": "Hello world!",
"sound": "cat.caf"
},
"url": http://example.com
}
#### 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
- Social.framework
- Accounts.framework
- AdSupport.framework
- src/ios/Frameworks/Parse.framework
- src/ios/Frameworks/FacebookSDK.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 url from the notification
parsePlugin.getNotification(function(url) {
alert(url);
}, function(e) {
alert('error');
});
</script>
Phonegap/cordova > 3.0.0