ios - 解析 iOS - 在特定时间发送推送通知

标签 ios objective-c parse-platform

我的应用程序的一部分目前允许用户使用 UIDatePicker 安排约会。他们按下一个按钮,我的后端对日期进行一些处理以存储约会数据,然后我使用以下代码发送推送:

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];

我想知道的是……有没有什么方法可以使用 Parse iOS SDK 来设置特定的推送传送时间?我还想在此方法中添加一个要在 UIDatePicker 日期前 1 小时发送的推送,内容类似于“提醒您与 x 的约会在 1 小时内”

提前致谢!

最佳答案

来自解析文档:

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.

IMO 的最佳做法是使用 Cloud Code,这样您就可以创建触发器(afterSave、afterDelete)或从您的 iOS 应用程序调用的函数。 由于 CloudCode 使用 Javascript SDK,您可以制作类似的东西:

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

关于ios - 解析 iOS - 在特定时间发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33811696/

相关文章:

ios - 用于短信和通话的 openUrl 替代方案

Objective-C 代码到 C 代码

objective-c - 我应该将我的事件指标发布声明放在 dealloc 中吗?

iOS Parse (Reduce API Requests) 每周在同一天执行一次函数

ios - 将此 Objective-C 代码从 Parse 教程转换为 Swift 是否等同于相同的检查

ios - 如何返回一个零自定义 UITableViewCell

c# - Xamarin:如何使用 YES 实现 NSDictionary

ios - 将 Realm 对象保存到数据库

ios - UICollectionView 重新加载单元格但不删除旧单元格

ios - 如何理解这个崩溃日志?信号发生器