【问题标题】:CloudKit for sending push notifications through cron jobs?CloudKit 用于通过 cron 作业发送推送通知?
【发布时间】:2014-07-29 13:12:20
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios database push-notification ios8 cloudkit


    【解决方案1】:

    对于这样的事情,您不会使用或考虑使用 Parse.com 似乎令人难以置信......

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

    注意 - Parse 现在位于 back4app.com。

    1) 解析是使用 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 相关的 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 是完全免费的(除非你有这么多用户,否则无论如何你都会发财)

    所以,我无法想象以任何其他方式按照您所说的去做 - 否则将是一场噩梦。希望对你有帮助

    【讨论】:

    • 仔细检查一下,我可以通过后端代码从网页上抓取数据并将其存储在云端,对吧?
    • 是的,我很确定这是可能的。所以,这里parse.com/docs/cloud_code_guide#networking 准确地解释了如何从互联网上获取一些页面。另请注意,您可以编写 webhook,以便“其他服务器可以呼叫您”...parse.com/docs/cloud_code_guide#webhooks 我建议 (a) 查看文档 (b) 不要犹豫,提出一个新问题,例如“我可以这样做with parse" 因为这个网站上有很多解析工程师
    【解决方案2】:

    服务器端

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

    但是..欢迎来到

    订阅

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

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

    Crons

    现在的问题是您的用户正在注册新帖子,但您不想每天都连接到 iCloud 仪表板以便通过添加记录来执行推送。这里的一个解决方案是在 mac 服务器上编写一个应用程序(我猜 mac mini 作为服务器将在 CloudKit 中变得更流行),每天添加一个新的DailyCKRecord

    限制

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

    【讨论】:

    • 正如你提到的,他们还没有发布这方面的所有信息。你知道我们什么时候可以完全使用这些功能吗?
    • “正如你所说,CloudKit 不允许服务器端代码......”确切地说,这就是 Parse 是 Parse ....
    • “你知道我们什么时候可以完全访问这些功能吗?” mahir,很难想象你会等待 CloudKit 做这样的工作,即“为 bAAs 制造”——只需选择你的毒药、Parse、Firebase、Applicase、Buddy 或其他任何东西。有 1000 篇关于“我应该选择哪些 bAA?!”的文章例如developereconomics.com/…
    • @JoeBlow 你说“这就是 Parse 是 Parse 的原因”。是的 Parse 非常强大,但我不担心 Apple。当我在 WWDC 与 CloudKit 人员交谈时,他们告诉我这是一项长期工作,他们为 CloudKit 计划了很多功能。 Parse 的真正优点将是多平台。只要您不能将 CloudKit 与任意 REST 请求一起使用,这对我来说就是个大问题。
    猜你喜欢
    • 2015-09-24
    • 2012-06-16
    • 2020-11-07
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    相关资源
    最近更新 更多