Mah*_*hir 5 database push-notification ios ios8 cloudkit
我正在创建一个大学餐饮菜单应用程序,我需要根据每日菜单发送推送通知。最初,我计划通过 Heroku 将用户数据存储在数据库中,并使用 cron 作业将数据库中的数据与日常菜单进行比较,并向用户发送适当的通知。
然而,在 Cloudkit 的消息发布后,我想我可以用它来管理我的代码中与服务器相关的部分。但是,经过仔细检查,Cloudkit 目前似乎能够存储数据,但不允许我们编写服务器端代码。
我想知道我是否正确解释了这个限制,或者实际上我是否可以在 CloudKit 上安排一个数据库,每天将其数据与在线菜单进行比较并发送适当的推送通知。
令人难以置信的是,您不会使用或考虑Parse.com来做这样的事情......
(如果不是 Parse,其他一些具有类似功能集的 bAA。)
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
}
Run Code Online (Sandbox Code Playgroud)
请注意,我正在调用云函数“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;
}
}
);
}
);
Run Code Online (Sandbox Code Playgroud)
(更完整的例子...... /sf/answers/1680757991/)
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"); }
}
);
}
Run Code Online (Sandbox Code Playgroud)
4) 在 nosql 环境中执行与食物数据库相关的所有操作都非常容易。没有什么比 Parse 方法更容易了
5)你可以免费获得整个后端(用于添加食物等)——通常需要几个月的工作
6)最后我猜 Parse 是相当免费的(除非你有这么多用户,否则你无论如何都会赚大钱)
所以,我无法想象以其他方式做你说的事——否则这将是一场噩梦。希望能帮助到你
| 归档时间: |
|
| 查看次数: |
2882 次 |
| 最近记录: |