CloudKit通过cron作业发送推送通知? [英] CloudKit for sending push notifications through cron jobs?

查看:138
本文介绍了CloudKit通过cron作业发送推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个大学餐饮菜单应用程序,我需要根据每日菜单发送推送通知。最初,我计划通过Heroku将用户数据存储在数据库中,并使用cron作业将数据库中的数据与每日菜单进行比较,并向用户发送适当的通知。

I'm creating a college dining menu app, in which I need to send push notifications based on the daily menus. Originally, I was planning on storing user data in a database through Heroku and using cron jobs to compare the data in the database with the daily menus and send appropriate notifications to users.

然而,在关于Cloudkit的新闻之后,我认为我可以使用它来管理我的代码中与服务器相关的部分。但仔细观察后,似乎Cloudkit目前能够存储数据,但不允许我们编写服务器端代码。

After the news on Cloudkit, however, I thought I could use that instead to manage the server-related part of my code. After closer inspection, though, it seems like Cloudkit is currently capable of storing the data, but does not allow us to write server-side code.

我想知道我是否正确解释了这个限制,或者我是否可以在CloudKit上安排数据库,以便每天将其数据与在线菜单进行比较,发送适当的推送通知。

I'm wondering if I interpreted this limitation correctly, or if I can, in fact, schedule a database on CloudKit to compare its data to the online menus each day and send appropriate push notifications.

推荐答案

您似乎不会使用或考虑 Parse.com 对于这样的事情......

It seems incredible you wouldn't use or consider Parse.com for something like this ...

(如果不是Parse,其他一些具有类似功能集的bAAs。)

(If not Parse, some other bAAs with a similar feature set.)

1)解析是使用iOS应用程序进行推送的最简单方法

1) Parse is the easiest possible way to do push with an iOS app

2)Parse的整个想法是你有云代码,而且非常简单,

2) the whole idea of Parse is that you have cloud code, and it's incredibly simple,

https://parse.com/docs/cloud_code_guide

你可以拥有云代码惯例,而且,你可以定期进行cron套路。这就是为什么每个人都在使用Parse!

you can have cloud code routines, and, you can have "cron" routines that go off regularly. it's why everyone's using Parse!

请注意,使用Parse从iOS调用云函数非常容易。

Note that it is super-easy to call "cloud functions" from iOS, with Parse.

这是一个例子,

-(void)tableView:(UITableView *)tableView
        commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
        forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    int thisRow = indexPath.row;
    PFUser *delFriend = [self.theFriends objectAtIndex:thisRow];

    NSLog(@"you wish to delete .. %@", [delFriend fullName] );

    // note, this cloud call is happily is set and forget
    // there's no return either way. life's like that sometimes

    [PFCloud callFunctionInBackground:@"clientRequestFriendRemove"
            withParameters:@{
                            @"removeThisFriendId":delFriend.objectId
                            }
            block:^(NSString *serverResult, NSError *error)
            {
            if (!error)
                {
                NSLog(@"ok, Return (string) %@", serverResult);
                }
            }];

    [self back];    // that simple
    }

注意我正在调用云函数clientRequestFriendRemove。所以这只是我编写的一段云代码,它位于我们的Parse帐户上,实际上这里是

Notice I'm calling a cloud function "clientRequestFriendRemove". So that's just a piece of cloud code I wrote and which is on our Parse account, in fact here it is

Parse.Cloud.define("clientRequestHandleInvite", function(request, response)
{
// called from the client, to accept an invite from invitorPerson

var thisUserObj = request.user;
var invitorPersonId = request.params.invitorPersonId;
var theMode = request.params.theMode;

// theMode is likely "accept" or "ignore"

console.log( "clientRequestAcceptInvite called....  invitorPersonId " + invitorPersonId + " By user: " + thisUserObj.id );
console.log( "clientRequestAcceptInvite called....  theMode is " + theMode );

if ( invitorPersonId == undefined || invitorPersonId == "" )
  {
  response.error("Problem in clientRequestAcceptInvite, 'invitorPersonId' missing or blank?");
  return;
  }

var query = new Parse.Query(Parse.User);
query.get(
  invitorPersonId,
    {
    success: function(theInvitorPersonObject)
      {
      console.log("clientRequestFriendRemove ... internal I got the userObj ...('no response' mode)");

      if ( theMode == "accept" )
        {
        createOneNewHaf( thisUserObj, theInvitorPersonObject );
        createOneNewHaf( theInvitorPersonObject, thisUserObj );
        }

      // in both cases "accept" or "ignore", delete the invite in question:
      // and on top of that you have to do it both ways

      deleteFromInvites( theInvitorPersonObject, thisUserObj );
      deleteFromInvites( thisUserObj, theInvitorPersonObject );

      // (those further functions exist in the cloud code)

      // for now we'll just go with the trick of LETTING THOSE RUN
      // so DO NOT this ........... response.success( "removal attempt underway" );
      // it's a huge problem with Parse that (so far, 2014) is poorly handled:
      // READ THIS:
      // parse.com/questions/can-i-use-a-cloud-code-function-within-another-cloud-code-function
      },
    error: function(object,error)
      {
      console.log("clientRequestAcceptInvite ... internal unusual failure: " + error.code + " " + error.message);
      response.error("Problem, internal problem?");
      return;
      }
    }
  );

}
);

(富勒示例...... https://stackoverflow.com/a/24010828/294884

(Fuller examples ... https://stackoverflow.com/a/24010828/294884 )

3)使Push发生从Parse中的云代码,这就是为什么每个人都使用它

3) it's trivial to make Push happen from the cloud code in Parse, again this is why "everyone uses it"

例如,这是一个与Push相关的Parse云代码片段...

For example, here's a Parse cloud code fragment that relates to Push ...

function runAPush( ownerQueryForPush, description )
// literally run a push, given an ownerQuery
// (could be 1 to millions of devices pushed to)
    {
    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.matchesQuery('owner', ownerQueryForPush);
    Parse.Push.send
        (
        {
        where: pushQuery,
        data:
            {
            swmsg: "reload",
            alert: description,
            badge: "Increment",
            title: "YourClient"
            }
        },
        {
        success: function()
{ console.log("did send push w txt message, to all..."); },
        error: function(error)
{ console.log("problem! sending the push"); }
        }
        );
    }

4)完成与食物数据库有关的所有事情都非常容易nosql环境。没有什么比Parse方法更容易

4) it's unbelievably easy to do everything relating to your food database, on a nosql environment. nothing could be easier than the Parse approach

5)你得到免费的整个后端(用于添加食物,无论如何) - 通常是几个月工作

5) you get the whole back end for free (for adding foods, whatever) - normally months of work

6)最后我猜Parse是免费的(直到你拥有这么多用户,无论如何你都会发财)

6) finally i guess Parse is quite free (until you have so many users you'd be making a fortune anyway)

所以,我无法想象你用别的方式做什么 - 否则将是一场噩梦。希望它有所帮助

So, I can't imagine doing what you say any other way - it would be a nightmare otherwise. Hope it helps

这篇关于CloudKit通过cron作业发送推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆