简体   繁体   中英

Parse iOS - Send push notification at specific time

A part of my app currently lets a user schedule appointments using a UIDatePicker. They press a button and my backend does some work with the date to store the appointment data, then I send a push using the following code:

NSString *objectID = [NSString stringWithFormat:@"user_%lu", (unsigned long)self.salespersonObject.userID];

PFPush *push = [PFPush new];
[push setChannel:[NSString stringWithFormat:@"%@",objectID]];

NSString *message1 = [NSString stringWithFormat:@"%@ sent you an appointment request. Visit your profile in the app to confirm", self.currentUser.fullName];

NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                                  message1, @"alert",
                                  @"Increment", @"badge",@"default",@"sound",
                                  nil];

[push setData: data];
[push sendPushInBackground];

What I'm wondering ... is there any way using the Parse iOS SDK to set a specific time for a push to be delivered? I'd like to also in this method add a push to be sent 1 hour prior to the UIDatePicker date that says something like "Reminder your appointment with x is in 1 hour"

Thanks in advance!

From Parse Doc :

Sending scheduled push notifications is not currently supported by the iOS or OS X SDKs. Take a look at the REST API, JavaScript SDK or the Parse.com push console.

The best thing to do IMO is to use Cloud Code, so you can make a trigger (afterSave, afterDelete) or a function that you call from your iOS App. Since CloudCode use the Javascript SDK you can make something like that:

var tomorrowDate = new Date(...);

var query = new Parse.Query(Parse.Installation);
query.equalTo('user_id', 'user_123');

Parse.Push.send({
  where: query,
  data: {
    alert: "You previously created a reminder for the game today" 
  },
  push_time: tomorrowDate
}, {
  success: function() {
    // Push was successful
  },
  error: function(error) {
    // Handle error
  }
});

Parse Push notification scheduling Guide

You can use parse Background jobs to schedule the push notification. Here is the link for documentation

There really isn't a whole lot you can do with the iPhone SDK and a closed app.

I would suggest that you assign the push to a channel, sending notifications is often done from the Parse.com push console, the REST API or from Cloud Code, you can also assign background jobs through this medium.

But if you want to stick to objective C as you don't mention any other languages; You can send Local Push Notifications natively but not through the PARSE SDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM