CloudKit通过cron作业发送推送通知?

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

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

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

看起来不可思议你不会使用或考虑Parse.com这样的事情……

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

注意 – Parse现在在back4app.com。

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

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

https://parse.com/docs/cloud_code_guide

你可以拥有云代码例程,并且你可以拥有定期关闭的“cron”例程。 这就是为什么每个人都在使用Parse!

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

这是一个例子,

-(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帐户上,实际上就是这样

 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

3) Parse中的云代码发生Push是微不足道的,这就是“每个人都使用它”的原因

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

 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方法更容易了

5)你可以免费获得整个后端 (添加食物,无论如何) – 通常是几个月的工作

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

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

服务器端

正如您所说,CloudKit不允许使用服务器端代码。

但是..欢迎来到

订阅

订阅概念是客户注册特定更新。 您可以创建一个名为Daily的记录类型,并让用户注册它。 您应该查看Apple文档和WWDC14video(即使订阅不详细,这是一个很好的起点)。

好处是推送通知与订阅概念相关联。 所以基本上你说:发送我的每个新的CKRecord类型Daily添加的通知。

Crons

现在问题是您的用户注册到新post但您不希望每天连接到iCloud Dashboard以通过添加记录来执行推送。 这里的一个解决方案是在mac服务器上编写应用程序(我猜mac mini,因为服务器将更受CloudKit欢迎),每天都会添加一个新的Daily CKRecord

限制

问题是AFAIK通知消息是在客户端写的,因此它不依赖于您发送的数据。