CloudKit for sending push notifications through cron jobs?

Mahir

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.

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.

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.

Fattie

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

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

NOTE - Parse is now at back4app.com.

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

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

https://parse.com/docs/cloud_code_guide

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

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

Here's an example,

-(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
    }

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;
      }
    }
  );

}
);

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

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

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) 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) you get the whole back end for free (for adding foods, whatever) - normally months of work

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Quartz Jobs的Cron作业语法

来自分类Dev

Disable cron jobs for a specific user

来自分类Dev

Android Parse Push Notifications很慢?

来自分类Dev

iOS:Apple Push Notifications理解

来自分类Dev

如何使用cron Jobs运行[Codeigniter]迁移?

来自分类Dev

关于Ubuntu 16.04上的Cron Jobs

来自分类Dev

Google App Engine上的Cron Jobs

来自分类Dev

cron git push与ssh键

来自分类Dev

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

来自分类Dev

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

来自分类Dev

如何测试Apple Push Notifications反馈服务?

来自分类Dev

Java Servlet does not stop Push notifications

来自分类Dev

WebApi应用程序的Apple Push Notifications

来自分类Dev

Windows Server上的Apple Push Notifications证书

来自分类Dev

如何测试Apple Push Notifications反馈服务?

来自分类Dev

PHP-一起使用Cron Jobs和GD

来自分类Dev

Django celery和Django cron-jobs用法之间的区别?

来自分类Dev

Azure Scheduler(预览版)与Cron Jobs + Web角色?

来自分类Dev

Android 中的 Firebase 云功能(Cron Jobs)可以吗?

来自分类Dev

实时聊天等应用的Signal R Vs Push Notifications

来自分类Dev

Apple Push Notifications:没有收到设备令牌?

来自分类Dev

WP7 Push Notifications returns null channel uri

来自分类Dev

Windows Server 2008上的Apple Push Notifications无法正常工作

来自分类Dev

Django多模型继承,django-push-notifications

来自分类Dev

如何在Bluemix Push Notifications服务中注册userId?

来自分类Dev

从Web角度看Notifications API和Push API之间的区别

来自分类Dev

适用于服务器的Apple Push Notifications服务

来自分类Dev

Apple Push Notifications在虚拟机上不起作用

来自分类Dev

使用Cron Jobs时未定义的REMOTE_ADDR-Laravel背包

Related 相关文章

热门标签

归档