【问题标题】:Sending silent push notifications using Parse.com使用 Parse.com 发送静默推送通知
【发布时间】:2015-01-14 03:23:28
【问题描述】:

我想知道是否有一种好方法可以使用 parse.com 服务向用户发送静默推送通知。

“静默”是指如果用户在应用程序中,则没有实际通知(如果用户不在应用程序中,我会发送正常通知),没有“警报”消息,什么也没有。只是一个离散的函数调用。

当用户在应用程序中时,我需要它来执行一些代码。

我在文档中读到我可以使用 cloudcode 但是

  1. 最好吗?
  2. 我该怎么做?没有其他解释。
  3. 是否有另一种更高效/移动友好的方式在用户不注意的情况下远程调用函数。

我应该使用 obj-C 代码吗?云代码?你能提供一个小例子吗? (我真的只需要在我的代码中默默地调用一个“刷新”函数,没什么花哨的)

非常感谢:)

【问题讨论】:

    标签: ios parse-platform push-notification silent


    【解决方案1】:

    我为我做这个并且它有效。

    第一: 在您的项目功能中转到“后台”并检查“远程通知”

    第二: 在你的 appdelegate 中确保有这个处理后台(静默)推送的方法。

    -(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
    
    //i handle the silent push here with a test on the userinfo's param.
    // if content-available = 1 do some stuff
    // else 
        // [PFPush handlePush:userInfo];
    
    }
    

    最后: 当您在推送中设置数据时,您必须添加 "content-available" = 1 并删除声音

     NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                              temp, @"alert",
                              @"Increment", @"badge",
                              @"", @"sound",
                              @1, @"content-available",
                              nil];
    

    NSDictionary *data =@{
          @"badge": @"Increment",
          @"alert": temp,
          @"sound": @"",
          @"content-available" :@1
          };
    

    【讨论】:

      【解决方案2】:

      您可以将云代码功能用于此类场景。 我不太了解解析云功能。这是您所期望的示例云代码。

      这就是定义云函数的方式

      Parse.Cloud.define("SomeFunction", function(request, response) {
      //Write queries as you need
      });
      
      Then call this cloud function as follows
      [PFCloud callFunctionInBackground:@"SomeFunction" withParameters:parameters block:^(id object, NSError *error) {
      //Add this function in some method & call the method wherever you needed, suppose if you need to update your app which has SwipingSideMenu like functionalities, for each time you click on the menu or side button call this cloud function. Thats it.
      }];
      

      【讨论】:

        【解决方案3】:

        也可以参考https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

        aps 字典也可以包含 content-available 属性。值为 1 的 content-available 属性让远程通知充当“静默”通知。当静默通知到达时,iOS 会在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。用户不会被告知因静默通知而产生的新信息或更改信息,但他们可以在下次打开您的应用时了解这些信息。

        【讨论】:

          猜你喜欢
          • 2018-02-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-07-21
          相关资源
          最近更新 更多