当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - swift 3 push notifications on parse

问题描述:

I am using Bitnami Parse Server on AWS to run a social media app. I am having trouble with push notifications.

I arranged my certificate, my domain id, push notification enable options etc.

I also foun this code below on eladnava. It actually worked but it is on js and one has to manually run the code to send a manual push notification.

However i really want to execute a push notification system within app to automate notification process. Like, if someone gets a message inside of app, they will have to get a push notification.

Do you have any idea how can i do that? Bear in mind that i'm using Parse.

var apn = require('apn');

// Set up apn with the APNs Auth Key

var apnProvider = new apn.Provider({

token: {

key: '', // Path to the key p8 file

keyId: '', // The Key ID of the p8 file

teamId: '', // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)

},

production: false // Set to true if sending a notification to a production iOS app

});

// Enter the device token from the Xcode console

var deviceToken = '';

// Prepare a new notification

var notification = new apn.Notification();

// Specify your iOS app's Bundle ID (accessible within the project editor)

notification.topic = '';

// Set expiration to 1 hour from now (in case device is offline)

notification.expiry = Math.floor(Date.now() / 1000) + 3600;

// Set app badge indicator

notification.badge = 3;

// Play ping.aiff sound when the notification is received

notification.sound = 'ping.aiff';

// Display the following message (the actual notification text, supports emoji)

notification.alert = 'notification message \u270C';

// Send any extra payload data with the notification which will be accessible to your app in didReceiveRemoteNotification

notification.payload = {id: 123};

// Actually send the notification

apnProvider.send(notification, deviceToken).then(function(result) {

// Check the result for any failed devices

console.log(result);

});

分享给朋友:
您可能感兴趣的文章:
随机阅读: