2014-06-09 64 views
4

我正在創建一個大學餐飲菜單應用程序,我需要根據每日菜單發送推送通知。最初,我打算通過Heroku將用戶數據存儲在數據庫中,並使用cron作業將數據庫中的數據與每日菜單進行比較,並向用戶發送適當的通知。CloudKit通過cron作業發送推送通知?

上Cloudkit消息傳出後,但是,我想我可以使用,而不是來管理我的代碼的服務器相關的部分。不過經過仔細觀察,似乎Cloudkit目前能夠存儲數據,但不允許我們編寫服務器端代碼。

我想知道如果我正確地解釋這一限制,或者如果可以,其實,安排在CloudKit一個數據庫,它的數據每天比較在線菜單併發送相應的推送通知。

回答

2

這似乎令人難以置信,你不會使用或考慮Parse.com這樣的事情......

(如果不分析,其他一些巴斯具有類似的功能集。)

注 - 解析現在在back4app.com。

1)解析是最簡單的方式做一推iOS應用

2)解析的整體思路是,你有云代碼,這是令人難以置信的簡單,

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.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)是微不足道的化妝推從解析雲代碼發生,再次這就是爲什麼「每個人都使用它」

例如,下面是涉及到一個推雲解析的代碼片段...

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環境下,與食物數據庫相關的一切都非常容易。沒有什麼能比的解析方法

5)你得到整個後端免費(用於添加食物,等等)更容易 - 通常個月的工作

6)最後我想分析是相當自由(直到你有這麼多的用戶,你會發財)

所以,我無法想象做你說的任何其他方式 - 這將是一場噩夢,否則。希望它有幫助

+0

只要仔細檢查一下,我就可以從網頁上抓取數據並將其存儲在雲端,只有後端代碼,對吧? – Mahir

+0

是的,我很肯定這是可能的。所以,這裏https://parse.com/docs/cloud_code_guide#networking它解釋瞭如何從互聯網上獲得一些頁面。請注意,你可以寫webhooks,以便「其他服務器可以打電話給你」... https://parse.com/docs/cloud_code_guide#webhooks我建議(a)檢查文檔(b)不要猶豫問一個新的問題,如「我可以做這個解析」,因爲這個網站上有很多解析工程師 – Fattie

2

服務器端

正如您所說的,CloudKit不允許服務器端代碼。

但是..歡迎

訂閱

訂閱概念是客戶特定的更新註冊。您可以創建一個名爲Daily的記錄類型,並讓用戶註冊。您應該檢查Apple documentation和WWDC14視頻(即使訂閱不詳細,這是一個很好的起點)。

好事是推送通知與訂閱的概念聯繫在一起。所以基本上你會說:發送我的通知爲Daily類型的每個新的CKRecord添加。

Crons

現在的問題是你的用戶是註冊到新的職位,但你不想要連接的icloud的儀表板每天都在爲了通過添加記錄進行推送。這裏的一個解決方案是編寫一個MAC服務器上的應用程序(我猜的Mac mini作爲服務器將成爲CloudKit更受歡迎),該補充每天都有新DailyCKRecord

限制

問題是AFAIK通知消息在客戶端寫的,所以它不依賴於你發送數據。

+0

正如你所說,他們還沒有公佈所有的信息。你知道我們什麼時候可以完全訪問這些功能嗎? – Mahir

+0

「正如你所說的CloudKit不允許服務器端代碼......」,這就是爲什麼Parse是Parse .... – Fattie

+0

「你知道我們什麼時候可以完全訪問這些功能嗎?」 mahir,這是不可思議的,你會等CloudKit去做這樣的工作,就是「爲了一個bAAs而生」 - 只要選擇你的毒藥,Parse,Firebase,Applicase,Buddy等等。有幾千篇關於「我應該選擇哪些bAAs?!」的文章例如http://www.developereconomics.com/backend-as-a-service-shootout-the-best-alternatives-to-parse/ – Fattie